I have a Node.js Express web application where a user can log in by posting his email address and password to a route /signin and when successful he receives a JWT token and stores it in his local storage.
I'm new to using JWT tokens for authorization and there's one thing I don't really understand how to do. How do I make sure that the user always send his JWT token with every request after a successful login?
I'm not using any front-end framework such as React or Vue.
You would need to send HTTP headers on every protected requests. The JWT token would be carried by the Authorization header like so:
Authorization: Bearer efh1340ufeileaf3148913-your-token
Then your backend would check if the token is valid and not expired and grant access to the data/route etc.
Take a look at https://jwt.io/introduction/, https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication and many many more on the subject
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With