Sajad Ahanger
Sajad Ahanger

Reputation: 65

How can get User Session token from getstream.io?

I want to add reactions to my Stream App. I saw this:

var userToken = client.createUserSessionToken(userId);

from stream documentation. I don't understand how to get this token. Do we have to make our own method for getting it or getstream.io has createUserSessionToken() method inbuilt. Can anybody confirm. Can I get one simple example how to get User Session Token.

Thanks in advance....

Upvotes: 0

Views: 2194

Answers (1)

mjduminy
mjduminy

Reputation: 143

You need to generate a user session token on your server and send it to the client.

First connect to getstream on your server (use your apiSecret here, but not on the client):

const client = getstream.connect(apiKey, apiSecret, appId, streamConnectOptions);
const userSessionToken = client.createUserSessionToken(userId);

Return the token to your front-end.

On the front-end connect without using the apiSecret:

const client = getstream.connect(apiKey, null, appId, streamConnectOptions);
const userSession = client.createUserSession(userSessionToken);

Then to add your reaction run:

// activityId = the id of the activity you are reacting to 
userSession.reactions.add('like', activityId, additionalData);

// OR
userSession.react('like', activityId, additionalData)

Upvotes: 1

Related Questions