Search code examples
node.jsauthorizationjwtexpress-jwt

How to verify routes with JWT token in NodeJS


Dears,

I'm trying to use JWT tokens to authorize my user. After user and password are confirmed at database, a JWT token is created. I also made a middleware to verify that token and used that middleware at some route that I've created. Testing this route with Postman inserting the token at the header, everything worked fine, but when I'm try to use this at the browser, the token is storage in the login header after I login, but when I redirect (using res.redirect('/dashboard')) I can't access the dashboard page because the token are only at login header, and not at dashboard header.

Do you know how to make that token available at all my environment? Or what's the best way to do that routes authorizations?

Thanks a lot for your help!


Solution

  • You can use session or cookies and store that token in there and set a time limit of expiry on them.