UserId of undefined and Follow with EKO-SDK

My project using eko-sdk 4.5.3 and we would like to using Follow API for our user.

I stuck at the beginning, the error said getFollowInfo is not a function. After I installed @amityco/js-sdk it’s working but still stuck with Cannot read properly 'userId' of undefined even if I harded code the userId as below.

So, is there an alternative way to using eko-sdk with Follow API and how to get rig of userId error


Hi @JustTod - getFollowInfo was just recently launched so can you check whether you’re on the most recent version of amityco/js-sdk ?
eko-sdk is already deprecated and does not support follow / unfollow feature

I’ve try to implement follow API, as you can see above.
I can get follow count by using getFollowInfo with currentUserId and targetUserId then getFollowCount with targetUserId

Then I tried to do it again with random string or dummy id like 12345678 for non-login user, but I can’t fix this error.

Is there another way to get follow count without login or using getFollowInfo?

Hi @JustTod - our SDK must always be logged in or it won’t have the access token to invoke any method. Can you share more detail on the use case on why do you want to use this with non-logged in users?

I found it out by using random string when register to SDK. It’s working fine now.
But I have some concern. Would this random string will effected this system in the future or cause any bug?

2021-10-29 at 13.28

Hi @JustTod - you’re randomly creating new users to connect to the service - this means you’re now creating new user every time getFollowInfo is invoked - and will cause lots of spam users + rack up MAU license charges.

1 Like

Thanks for your information. We will create dummy user for non-login user to get the follow info.

And another problem for a newbie like me. I can’t get a correct data from the live object right on time. It seems like the program return before receive the data from live object.

This is my code.
2021-11-01 at 10.46

Also, when I use the getFollowInfo I already have async / await but it still didn’t synchronous yet.
2021-11-01 at 10.53

Hi @JustTod - LiveObject is based on callback pattern and you need to wrap Promise around the object for it to work with await. You can use the sample code below:

export const asynchronize = async (liveThing, immediately = true) => {
    if (immediately && ((liveThing.models && liveThing.models.length) || liveThing.model))
        return liveThing.models || liveThing.model; // data is already loaded and can be returned right away

    return new Promise((resolve, reject) => {
        // we wrap the resolve in setTimeout(0) to allow 'hasMore' to refresh for live collection (reactive related bug.)
        liveThing.once("dataUpdated", (data) =>
          setTimeout(() => {
          }, 0)

now you can use the function as followed:

const status = await asynchronize(liveFollowStatus)
1 Like