Server events authentication in JS and TS

Hi everybody!
I need get server events from my service, but I don’t know how to do this for TS and JS.
I understand correctly, after authentication, I receive messages for my user?
Оr should I do like the c# client?

You just need to authenticate with the browser once as the JsonServiceClient/ServerEventClient automatically shares and sends the same cookies and authenticated user session that’s established with the browser.

So if you authenticate via any means normally, you will connect as the authenticated user to the event-stream. e.g. hitting the /auth/twitter, /auth/facebook, /auth/github routes will authenticate via OAuth and when it redirects back to the home page it will connect as the authenticated user.

Some options for authenticating with the JsonServiceClient, e.g:

var client = new JsonServiceClient(baseUrl);

//Basic Auth
client.userName = userName;
client.password = password; AuthOnlyRequest());

var request = new Authenticate();
request.provider = "credentials";
request.userName = userName;
request.password = password;

var authResponse = await Authenticate());

//Using JWT
var jwtToken = authResponse.bearerToken;

Note: setBearerToken() was just added in v0.0.28

1 Like