Sup_File/config/passport.js
2018-05-03 16:15:57 +02:00

29 lines
861 B
JavaScript

var JwtStrategy = require('passport-jwt').Strategy,
ExtractJwt = require('passport-jwt').ExtractJwt;
// load up the user model
var User = require('../models/user');
var config = require('../config/database'); // get db config file
module.exports = function(passport) {
var opts = {};
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderWithScheme("jwt");
opts.secretOrKey = config.secret;
passport.use(new JwtStrategy(opts, function(jwt_payload, done) {
User.findOne({id: jwt_payload.id, username: jwt_payload.username}, function(err, user) {
if (err) {
return done(err, false);
}
if (user) {
console.log('jwt_payloadddd : ' + JSON.stringify(jwt_payload));
console.log('useruseruser : ' + JSON.stringify(user));
done(null, user);
} else {
done(null, false);
}
});
}));
};