# \[Web + Amity SDK\] About Follow with multiple registerSession

**URL:** <https://forum.social.plus/t/web-amity-sdk-about-follow-with-multiple-registersession/358>\
**Category:** Web\
**Tags:** technical\
**Created:** [November 26, 2021, 6:15am UTC](https://forum.social.plus/t/web-amity-sdk-about-follow-with-multiple-registersession/358 "2021-11-26T06:15:33Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlezip](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@tlezip](https://forum.social.plus/u/tlezip)\
**Post date:** [November 26, 2021, 6:15am UTC](https://forum.social.plus/t/web-amity-sdk-about-follow-with-multiple-registersession/358/1 "2021-11-26T06:15:34Z")

</div>

Currently we’re trying to implement Follow with Amity SDK on our UGC profile page  
Example: [Whynottravel | Creator Profile at TrueID In-Trend](https://creators.trueid.net/@whynottravel)

**Here are our use cases**

- When both non logged in & logged in user visit the page, the following & followers count should show up.
- Our site can’t know at the first load that user already logged in or not, need to wait for a moment. so on the first load page will be non logged in user.

**Non Logged In**

- When non logged in user visit the page, Follow Button should show as “Follow” (If user click at follow button, login modal will show up).

**Logged In**

- If logged in user already followed the creator in the profile page, Follow Button should show as “Following”
- Logged in user should be able to click to Follow/Unfollow.

**So here’re the way we decided to do**

- At the first load page, we generate random string and registerSession with that randomString, so the page can load followings/followers count, and It’ll get for the count.
- After 1-2 secs our site will know if there’s logged in user or not. In-case there’s logged in user, so our site will do log-in automatically. then our site will unregisterSession the generatedString. then it’ll registerSession with correct userId (ssoid)
- After registered with correct userId, our site will try to check if logged in user is following the creator on the page.

**Here are the problems we found**

1. After we tried to check if logged in user is following the creator on the page, sometimes it checked with generated string user, not correct userId. even if we already unregistered generated string.
2. We tried to log and it showed that registerSession with correct userId is success (connectionStatus = ‘connected’). But after we click to follow user, it showed that generated string user make follow request to user on profile page. not correct userId make request to follow user.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/amity/original/1X/899dc0535e740ecbffa8202f4be28b7cc75a65e5.jpeg)  
This image shows step to register, unregister, querying data, receiving data

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/amity/original/1X/460829fe87e93f1162ab078c475d83b58db33277.png)  
This image shows that the last query is check if generatedString is following 71657211.  
But what it should be is, it should check if 21996792 is following 71657211. Because it tried to get follow status after registered 21996792.

Any idea about this?

---

<div class="post-metadata">

**Author:** ![touchaponk](https://avatars.discourse-cdn.com/v4/letter/t/ec9cab/32.png) [@touchaponk](https://forum.social.plus/u/touchaponk)\
**Post date:** [November 29, 2021, 6:54am UTC](https://forum.social.plus/t/web-amity-sdk-about-follow-with-multiple-registersession/358/2 "2021-11-29T06:54:27Z")

</div>

Hi @tlezip - we would strongly advise against generating random user ID every time a page is loaded - this causes unnecessary workload especially in production when you have Secure Mode( [https://docs.amity.co/console/settings/security#secure-mode](https://docs.amity.co/console/settings/security#secure-mode) ) turned on since every page load will incur 1-2 calls to your backend to generate `authToken`+ another 1-2 calls to init session on our side. This also will cause your user IDs to be very bloated.

May I advise you to only init the SDK when the page has finished checking the identity of the user

---

<div class="post-metadata">

**Author:** ![tlezip](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@tlezip](https://forum.social.plus/u/tlezip)\
**Post date:** [November 29, 2021, 9:23am UTC](https://forum.social.plus/t/web-amity-sdk-about-follow-with-multiple-registersession/358/3 "2021-11-29T09:23:28Z")

</div>

I’m not sure if we can do that. I’ll talk with team about that.

But If we can do it, for non logged in user, we’ll still have to register with generated string anyway. So we’ll be able to show followings/followers count. And that’ll cause the same problem right?

Also if user still not log-in yet, So our system will register with generated string. But If user click log in button after that, after logged in success. we’ll have to call registerSession one more time, and I think it might have problem like I mentioned above.

I think my question are how come the case above happened? and how can I fix it?

---

<div class="post-metadata">

**Author:** ![Azwind](https://avatars.discourse-cdn.com/v4/letter/a/b5e925/32.png) [@Azwind](https://forum.social.plus/u/Azwind)\
**Post date:** [November 30, 2021, 3:16am UTC](https://forum.social.plus/t/web-amity-sdk-about-follow-with-multiple-registersession/358/4 "2021-11-30T03:16:08Z")

</div>

> [@tlezip](#):
>
> erSession with that randomString, so the page can load followings/followers count, and It’ll get for th

hi @tlezip !  
I implemented for you simple playground [JS SDK debugging doodle - JSFiddle - Code Playground](https://jsfiddle.net/ybwh8f7u/). There I connect with not existed user1 (random user id), then call unregisterSession and connect with user2 (existing). So, on second connection followInfo status changed. Could you tell if this works for you ? If not could you provide more details ?

---

<div class="post-metadata">

**Author:** ![tlezip](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@tlezip](https://forum.social.plus/u/tlezip)\
**Post date:** [November 30, 2021, 4:21am UTC](https://forum.social.plus/t/web-amity-sdk-about-follow-with-multiple-registersession/358/5 "2021-11-30T04:21:19Z")

</div>

As I tried, sometimes it works, sometimes it’s not.  
you can see at this log example.

This step it register with randomString and try to get follow count data  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/amity/original/1X/5dc9a57622742432bbf7c999bed40da50b341361.png)

Then our system can detect logged in user so it unregister randomString  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/amity/original/1X/8e82ddf84c723d6293564c1c91a5c389c1d430fd.png)

21996792 is correct user, so log seem correct right?  
but when I click to follow user here are the response  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/amity/original/1X/efa12fc27102ee8e6191c96ca573f71ec6b7f0cc.png)

It’s showing that randomString just followed the target user, not 21996792

---

<div class="post-metadata">

**Author:** ![Azwind](https://avatars.discourse-cdn.com/v4/letter/a/b5e925/32.png) [@Azwind](https://forum.social.plus/u/Azwind)\
**Post date:** [November 30, 2021, 4:44am UTC](https://forum.social.plus/t/web-amity-sdk-about-follow-with-multiple-registersession/358/6 "2021-11-30T04:44:34Z")

</div>

@tlezip thank you for reply. Could you show the code that relates to sending follow request ?

---

<div class="post-metadata">

**Author:** ![Azwind](https://avatars.discourse-cdn.com/v4/letter/a/b5e925/32.png) [@Azwind](https://forum.social.plus/u/Azwind)\
**Post date:** [November 30, 2021, 4:54am UTC](https://forum.social.plus/t/web-amity-sdk-about-follow-with-multiple-registersession/358/7 "2021-11-30T04:54:13Z")

</div>

@tlezip could you also check if you see correct connection inside Network tab. When you do registerSession each call of this function create new socket connection.

---

<div class="post-metadata">

**Author:** ![tlezip](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@tlezip](https://forum.social.plus/u/tlezip)\
**Post date:** [November 30, 2021, 5:42am UTC](https://forum.social.plus/t/web-amity-sdk-about-follow-with-multiple-registersession/358/8 "2021-11-30T05:42:22Z")

</div>

As I tried, most of it will create only one socket. it should be 2 sockets right? (one for randomString, one for actual user)

If so, do you have any idea why it create only one socket?

here is the code for registering/unregistering

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/amity/original/1X/5012475bc888595f6a2288c7048c6d130553deba.png)

here is the code for making follow request / getting follow count

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/amity/original/1X/f0a5a882ccfc3b9f1d10df30810594ae55e69e1b.png)

here is the code when we call 2 files above  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/amity/original/1X/30bb7e9dbcf184a90c2df84bc67e8728cfa58d4e.png)

Also at Follow Button component, we tried to get FollowStatus like this  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/amity/original/1X/d47c91111de501c007364fa6d54c5ce934477e35.png)

---

<div class="post-metadata">

**Author:** ![Azwind](https://avatars.discourse-cdn.com/v4/letter/a/b5e925/32.png) [@Azwind](https://forum.social.plus/u/Azwind)\
**Post date:** [November 30, 2021, 7:17am UTC](https://forum.social.plus/t/web-amity-sdk-about-follow-with-multiple-registersession/358/9 "2021-11-30T07:17:12Z")

</div>

@tlezip could you try to move AmityClient.on(‘connectionStatusChanged’) handler out of useEffect ? This can be an issue.

---

<div class="post-metadata">

**Author:** ![tlezip](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@tlezip](https://forum.social.plus/u/tlezip)\
**Post date:** [November 30, 2021, 9:41am UTC](https://forum.social.plus/t/web-amity-sdk-about-follow-with-multiple-registersession/358/10 "2021-11-30T09:41:23Z")

</div>

When I moved  
AmityClient.on(‘connectionStatusChanged’) and const AmityClient out of useEffect

Then I got error  
ASCWebSDK: Only one instance of the SDK Web Client can be created

I think it’s because of the useAmity state has been updated, so It’ll try to create Amity instance again.

So I tried to put both of that into another useEffect that will be run only one time and store client into state.

When I try to test again. I still see that there’s only one socket.

---

<div class="post-metadata">

**Author:** ![Azwind](https://avatars.discourse-cdn.com/v4/letter/a/b5e925/32.png) [@Azwind](https://forum.social.plus/u/Azwind)\
**Post date:** [December 1, 2021, 3:15am UTC](https://forum.social.plus/t/web-amity-sdk-about-follow-with-multiple-registersession/358/11 "2021-12-01T03:15:59Z")

</div>

@tlezip thank you for detailed report. Finally I reproduced the issue. I will try to find the solution.

---

<div class="post-metadata">

**Author:** ![tlezip](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@tlezip](https://forum.social.plus/u/tlezip)\
**Post date:** [December 13, 2021, 3:51am UTC](https://forum.social.plus/t/web-amity-sdk-about-follow-with-multiple-registersession/358/12 "2021-12-13T03:51:44Z")

</div>

Do you have any updates?

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [December 13, 2021, 4:41am UTC](https://forum.social.plus/t/web-amity-sdk-about-follow-with-multiple-registersession/358/13 "2021-12-13T04:41:14Z")

</div>

Hi @tlezip the team is still working on it, we will update you asap when there is an update. We’re sorry for the inconvenience 🙏🏻

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [December 22, 2021, 12:50pm UTC](https://forum.social.plus/t/web-amity-sdk-about-follow-with-multiple-registersession/358/14 "2021-12-22T12:50:34Z")

</div>

Hello @tlezip we have found a bug on our side and we are addressing it. We will inform you once it is fixed. However, we still advise that this is not the effective way to implement 🙏🏻😊 Thank you.

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [January 25, 2022, 12:41pm UTC](https://forum.social.plus/t/web-amity-sdk-about-follow-with-multiple-registersession/358/15 "2022-01-25T12:41:27Z")

</div>

Hello @tlezip we have released the fix for this bug, thank you 🙏
