Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct use of passport-jwt & deserializeUser #217

Closed
dn-l opened this issue Sep 24, 2020 · 1 comment
Closed

Correct use of passport-jwt & deserializeUser #217

dn-l opened this issue Sep 24, 2020 · 1 comment

Comments

@dn-l
Copy link

dn-l commented Sep 24, 2020

Hi, here's my code:

async function jwtStrategy (jwtPayload, done) {
  const user = await User.findById(jwtPayload.sub)
    .deepPopulate('one.two.three')
    .exec()
    .catch(errorHandler(done))
  if (!user) {
    return done(createHttpError(401))
  }
  done(null, user)
}

passport.use(new JwtStrategy(jwtStrategyOptions, jwtStrategy))

passport.deserializeUser(async (id, done) => {
  const user = await User.findById(id)
    .deepPopulate('one.two.three')
    .exec()
    .catch(errorHandler(done))
  done(null, user)
})

It works great however i noticed that i make too make requests (populate). On every api request i get passport.deserializeUser executed and jwtStrategy straight after. What's the correct usage here?

@dn-l
Copy link
Author

dn-l commented Sep 25, 2020

I ended up removing session support => deserialize became redundant

@dn-l dn-l closed this as completed Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant