We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2f9059e commit 62c18c2Copy full SHA for 62c18c2
src/midlewares/passport.ts
@@ -0,0 +1,20 @@
1
+import { Strategy, StrategyOptions, ExtractJwt } from 'passport-jwt'
2
+import config from '../config/config'
3
+import User from '../models/User'
4
+
5
+const opts: StrategyOptions = {
6
+ jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
7
+ secretOrKey: config.secretKey
8
+}
9
10
+export default new Strategy(opts, (payload,done)=>{
11
+ try {
12
+ const user = User.findById(payload.id)
13
+ if (user) {
14
+ return done(null,user)
15
+ }
16
+ return done(null,false)
17
+ } catch (error) {
18
+ console.log(error)
19
20
+})
0 commit comments