Reputation: 552
I tried to implement jwt(JsonWebToken) into node express through mongodb. In the time of generating the token I store the token value into database collection and retrieve token from mongodb and pass it to the next pages And also set a logout option, When I trigger the logout the the token field in the database is got flushed and no more actions performed after this. But the problem is when more than one users logged in the application it is not possible.Because when I clicked logout it clears all the tokens. How can I solve this correctly..?
Upvotes: 1
Views: 4720
Reputation: 19
Just put the req.session.token, by passing token = jwt.sign();
but only after authentication.
And on logout you can actually delete req.session.token
Upvotes: 1
Reputation: 1364
You can store it in the cookies/session. And when logging out, you can delete those values. Should do the trick. Comment: This trick would work fine if you are not developing an app for mobile phones.User should be able to logout from all devices once he clicked logout button just like facebook asks before logging out. Every user would have his own user_id and his own token(you can set the expiry time as you want),so when flushing take the user_id and flush that particular token.
Upvotes: 1