DEV Community

Discussion on: Using Cookies with JWT in Node.js

 
franciscomendes10866 profile image
Francisco Mendes

The biggest difference when saving the JWT in a cookie would be the fact that when making an http request, the cookie would be sent with the request. But if you store the JWT in localstorage, you would have to send it explicitly with each http request. 🧐

Thread Thread
 
hasnaindev profile image
Muhammad Hasnain

Ahan, I understand. I wasn't sure if this was for a server-side website. Meaning, we don't have to use packages like Passport.js with this approach.

Thread Thread
 
franciscomendes10866 profile image
Francisco Mendes

Exactly. If you do it this way you end up with less boilerplate in your Api. The use of Passport.js is not incorrect, I just like to show that we can make simple and functional implementations. 🥸

Thread Thread
 
aziz477 profile image
aziz477

please can you tell me what is the exact role of passport strategy next to the normal jwt?

Thread Thread
 
franciscomendes10866 profile image
Francisco Mendes

Passport is a middleware with a good level of abstraction, for example, with jwt you wouldn't have to write that much code. In addition to being faster to implement, it is also the simplest. However, business rules can change from project to project so I advise people to know how to do a simple setup.