hagopj13 / node-express-boilerplate

A boilerplate for building production-ready RESTful APIs using Node.js, Express, and Mongoose
MIT License
6.99k stars 2.05k forks source link

Access token is not invalidated after logout #176

Closed markvital closed 2 years ago

markvital commented 2 years ago

It looks like a user is able to access resources that need authentication even after access/refresh tokens are removed (logout event)

To reproduce:

I assume after user logout, access token associated with current refresh token should become invalid, correct?

markvital commented 2 years ago

Found this on auth0 website:

Access tokens cannot be invalidated: they are designed to be self contained, not requiring a check with Auth0 to validate, so there is no way to invalidate them.

For this reason, access tokens should have a short lifetime.

So it looks like access token should not be invalidated after logout, only refresh token

jleei commented 2 years ago

You can add a field to the user table that restricts access tokens. Then check this field in the passport's config, if true, restrict the user to use the access token