Skip to content
This repository has been archived by the owner on Mar 22, 2022. It is now read-only.

JWT is not sent after socket reconnection #272

Closed
Mangatt opened this issue Aug 15, 2016 · 5 comments
Closed

JWT is not sent after socket reconnection #272

Mangatt opened this issue Aug 15, 2016 · 5 comments

Comments

@Mangatt
Copy link

Mangatt commented Aug 15, 2016

I have stumbled upon strange behavior - after socket is disconnected and connected again, new realtime events does not contain JWT (hook.params.token) which renders all reconnect process useless (= you have to authorize user again manually).

What to do about this?

@daffl
Copy link
Member

daffl commented Aug 15, 2016

At the moment have to store the token and send the authenticate event. When using the client this can be done with calling app.authenticate() again after a disconnect just like when the application is loading initially. The next version should probably try to do this automatically.

@tkornblit
Copy link

I'm also running into this issue. I've even done the following:

this.app = feathers()
        .set("user", JSON.parse(localStorage.getItem('user')))
        .set("token", localStorage.getItem('token'))
        .configure(socketio(socket))
        .configure(hooks())
        .configure(authentication({storage: localStorage}))

Which I thought was going to be a clever hack.

The client-side hook picks it up successfully. But for some reason it's not available in the hook on the server side.

Using app.authenticate isn't going to work for me because i'm using the local authentication option and not JWT.

Any ideas?

@Mangatt
Copy link
Author

Mangatt commented Aug 19, 2016

@tkornblit I have solved this issue with following code:

const socket = io('http://localhost:3030/');

const app = feathers()
    .configure(hooks())
    .configure(socketio(socket))
    .configure(authentication({ storage: window.localStorage }));

socket.on('reconnect', () => {app.authenticate();});

Hope this helps.

@tkornblit
Copy link

Thanks mate. This was helpful.

Tom Kornblit
Founder of Sage http://www.sagebots.com/
Personal Blog http://blog.tomkornblit.com/ | LinkedIn https://www.linkedin.com/in/tomkornblit | Twitter https://twitter.com/tkornblit

On Aug 19, 2016, at 2:17 AM, Mangatt notifications@github.com wrote:

@tkornblit https://github.com/tkornblit I have solved this issue with following code:

const socket = io('http://localhost:3030/');

const app = feathers()
.configure(hooks())
.configure(socketio(socket))
.configure(authentication({ storage: window.localStorage }));

socket.on('reconnect', () => {app.authenticate();});
Hope this helps.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub #272 (comment), or mute the thread https://github.com/notifications/unsubscribe-auth/AB7b-YAUxpQXj5llLXrBe8bwtf3LBNnXks5qhUpwgaJpZM4JkXY3.

@marshallswain
Copy link
Member

Closing this in favor of feathersjs-ecosystem/authentication-client#2

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

4 participants