Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Refresh socket.request.user when user authenticates #132

Open
alexwohlbruck opened this issue Mar 26, 2017 · 6 comments
Open

Refresh socket.request.user when user authenticates #132

alexwohlbruck opened this issue Mar 26, 2017 · 6 comments

Comments

@alexwohlbruck
Copy link

As of right now, when an unauthenticated user goes my site and then logs in, the socket.request.user variable remains empty for each emit afterward, unless the page is refreshed (Using an Angular single page app). How do I get the updated data when a user logs in or out?

@zerefel
Copy link

zerefel commented Mar 27, 2017

I've had this issue for quite some time as well. A clean solution would be greatly appreciated, as this makes this library not the best choice for SPAs.

@Sannis
Copy link

Sannis commented Mar 27, 2017 via email

@jfromaniello
Copy link
Owner

Make sure you initiate a new socket.io conneciton after the user logins.

In new versions of socket.io:

// new socket.io:
var socket = io.connect(socketUrl,{'forceNew': true });

// old socket.io:
var socket = io.connect(URL, {'force new connection': true });

You need to force a new, otherwise socket.io reuses the connection initiated before authentication.

@alexwohlbruck
Copy link
Author

Okay, that works. Should I also disconnect after they sign out?

@savoiebz
Copy link

Hello team,

I know this issue is old but I would appreciate if we could give it a bit more attention.

Could it be possible to integrate a method bound to the socket that updates the stored values of the session user?

Currently, PasseportJS uses the req.login function that allows you to update the user informations bound to the request.user object.

It is very usefull in a SPA when a user goes to his settings and updates important information. Don't need to reload browser or anything.

I believe this library would profit very positively from a similar approach.

-Thank you

@savoiebz
Copy link

Litle update:

After looking online if there was a method bound directly to socket.io to refresh the handshake I found this:

socket.handshake.session.reload(function(err) {
  // Session is refreshed here and socket.request.user values are updated, 
  // if they previsouly changed in the PasseportJS session
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants