forked from bloominstituteoftechnology/back-end-project-week
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassport.js
More file actions
23 lines (21 loc) · 632 Bytes
/
passport.js
File metadata and controls
23 lines (21 loc) · 632 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const JwtStrategy = require('passport-jwt').Strategy;
const ExtractJwt = require('passport-jwt').ExtractJwt;
const User = require("./models/User");
const secretJWT = "I love programming";
const opts = {};
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();
opts.secretOrKey = secretJWT;
module.exports = passport => {
passport.use(
new JwtStrategy(opts, (jwt_payload, done) => {
User.findById(jwt_payload.id)
.then(user => {
if (user) {
return done(null, user);
}
return done(null, false);
})
.catch(err => console.log(err));
})
);
};