0

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....

  • The line of code you pasted is exactly what you need to create a session token; Please keep in mind at at the moment user sessions and reactions are only supported by the JS client – Tommaso Barbugli Sep 01 '18 at 09:01

1 Answers1

1

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)
mjduminy
  • 143
  • 2
  • 7