Created
January 8, 2018 09:29
-
-
Save mrhm-dev/e9b47c7c1363c910f7e72773fca99063 to your computer and use it in GitHub Desktop.
Passport JWT strategy configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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