Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send JWT along with every request after successful login?

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.

like image 753
Hallur A. Avatar asked Sep 15 '25 17:09

Hallur A.


1 Answers

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

like image 121
t3__rry Avatar answered Sep 17 '25 09:09

t3__rry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!