-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpassport.js
31 lines (29 loc) · 957 Bytes
/
passport.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const JwtStrategy = require('passport-jwt').Strategy;
const ExtractJwt = require('passport-jwt').ExtractJwt;
const passport = require('passport');
const config = require('./config');
const Team = require('./models/team');
let opts = {};
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();
opts.secretOrKey = config.secret;
passport.use('jwt', new JwtStrategy(opts, function(jwt_payload, done) {
Team.findOne({_id: jwt_payload.sub}, function(err, team) {
if (err) {
return done(err, false);
}
if (team) {
return done(null, team);
} else {
return done(null, false);
// or you could create a new account
}
});
}));
// function(req) {
// let string = (req.headers.authorization).split(' ');
// console.log(string);
// if(req && req.headers.authorization) {
// return (string[1]+ ' ' + string[2]);
// }
// return null;
// }