Passport seems like a great option for simple authentication, unobtrusive and not hard to setup. I'm building a MEAN stack that authenticates using JWT so I looked to Passport JWT. However there's a few things I'm confused about.
1) Am I correct in assuming that Passport JWT is only used for authenticating requests, not for generating a valid jwt? That is, should it only be used for validating the presence of a token?
2) What's the difference between passport.authorize
and passport.authenticate
? And when should I use one over the other?
3) I have 3 routes I'm using for authentication related matters, login
, signup
, and authenticate
.
login
will check if the user email/password combo exists and matches and then generate a token for the client.
signup
will check to make sure the email doesn't already exist and then generate a token for the client.
Now for authenticate
this is where I get a little mixed up. Would I even need an authenticate
route if I already have login
and signup
? If anything, it seems like authenticate would be the function that I pass into passport.use
for the JWT strategy and then login
and signup
with the possible addition of a verify_token
route would be my only unprotected routes, where everything else would have a call to passport.authenticate
or passport.authorize
.