Gà Rù
Gà Rù

Reputation: 291

NodeJs Authentication????

I'm building a apllication with NodeJs. My app have 1 login form.

When user A login successfully, I save username in session of Express.

And now I want when another user is B, login with that username, the user A 'll be logout, he 'll have a messager alert 'This account was login in another place' and user B is login.

Anyone can help me please. Thanks

Upvotes: 2

Views: 296

Answers (1)

Martijn de Langh
Martijn de Langh

Reputation: 415

Save the the user in for example a database, create a token for the specific login session and add this to the user in de database. Switch this token each login.

With each request check the authentication token (you can store tokens in local storage), then you can check if the token is up to date (active) or not.

Once another user logs in the token will change, and so on.

If you want the logout to happen without making a request you will need to use socket.io

Upvotes: 5

Related Questions