So i recently used jwt to make an auth system in my server, everything worked great but when i wanted to make a logout route i realized something:
jwt cannot be unvalidated soo instead what i did is stored these tokens along with the logged in user's id in mongodb, so everytime the user login the token gets saved to the DB but hashed using sha256 algorithm in a different collection.
-Im using it only for verification purposes so when we hit a protected route for example we check if the current token that we have (from either the header or a cookie) is valid in the DB, and then we validate it if found using jwt.verify()
and other verification steps
im basically whitelisting tokens.
benefits:
-whenever i want to logout a user i simply remove that token from the DB
-or remove all tokens with the current profile id if i want to logout all the users with this account...
Now here's my question:
- Is my approach doable ?
- Is it bad for security (keep in mind that tokens are stored hashed) ?