Reputation: 261
I have seen multiple online tutorial which are using Passport.js along with json web token for authentication purpose. My question is why we needs to use passport.js when we can use only use jwt to create and authenticate a token. To create Token : jwt.sign() To Verify Token :jwt.verify()
Upvotes: 0
Views: 919
Reputation: 38
Heya! so JWT and Passport.js both have separate purposes. JWT is a middleware that deals with authorization, whereas Passport.js handles authentication (login/logout)
A JsonWebToken (JWT) is generated after authentication & is sent to the client, in which the client will return the JWT with each HTTP request to be validated to grant access to resources.
Since they are not equal and each has a separate purpose, there is no reason to choose one over the other. They do, however, work well together to give your express web application a robust mode of access control.
Hope that was helpful!
Upvotes: 2