Skip to content

Instantly share code, notes, and snippets.

@mrhm-dev
Created January 8, 2018 09:29
Show Gist options
  • Save mrhm-dev/e9b47c7c1363c910f7e72773fca99063 to your computer and use it in GitHub Desktop.
Save mrhm-dev/e9b47c7c1363c910f7e72773fca99063 to your computer and use it in GitHub Desktop.
Passport JWT strategy configuration
module.exports = function(passport){
let opts = {};
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderWithScheme("jwt");
opts.secretOrKey = config.secret;
passport.use(new JwtStrategy(opts, (jwt_payload, done) => {
User.getUserById(jwt_payload.data._id, (err, user) => {
if(err){
return done(err, false);
}
if(user){
return done(null, user);
} else {
return done(null, false);
}
});
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment