msmfsd msmfsd - 6 months ago 51
Node.js Question

Do I need to use express sessions along with passport and JSON web tokens for auth?

I looked for documentation/posts on this subject and found none so far.

I have a working node/express/mongo api with passport-jwt strategy with passports' session option set to false and I am not using express sessions middleware at all. I notice many guides also use session when using passport for authentication. My question:


  • With passport-jwt do I also need to use express session as well?

  • If so how?


Answer

The answer here is no, express session is not needed as long as you are just using JWT auth and no other auth. It is important to configure passport session though:

app.use(passport.session());
Comments