-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassport.js
41 lines (38 loc) · 916 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
32
33
34
35
36
37
38
39
40
41
const JwtStrategy = require('passport-jwt').Strategy;
const ExtractJwt = require('passport-jwt').ExtractJwt;
const User = require('./Models/User');
const config = require('./secret');
// Setup work and export for the JWT passport strategy
module.exports = function(passport)
{
const opts =
{
jwtFromRequest: ExtractJwt.fromAuthHeader(),
secretOrKey: config.secret
};
passport.use
(
new JwtStrategy
(
opts,
function(jwt_payload, done)
{
console.log(jwt_payload);
const jwtUsername = jwt_payload.un;
User.findOne
(
{Username:jwtUsername},
function(err, user)
{
if(err)
return done(err, false);
if(user)
done(null, user);
else
done(null, false);
}
);
}
)
);
};