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
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.
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.
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.
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 ) 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
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?
hi @tlezip !
I implemented for you simple playground JS SDK debugging doodle - JSFiddle - Code Playground. 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 ?
@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.
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.