Last active
June 29, 2020 14:03
-
-
Save kianaditya/b1482b5f85d89b683af91a06adec27c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Strategy, ExtractJwt } = require('passport-jwt') | |
const secret = 'secret' | |
const db = require('../models') | |
const options = { | |
jwtFromRequest: ExtractJwt.fromAuthHeaderWithScheme('JWT'), | |
secretOrKey: secret, | |
} | |
const jwtStrategy = new Strategy(options, async (payload, done) => { | |
try { | |
const user = await db.User.findOne({ where: { email: payload.email } }) | |
if (user) { | |
return done(null, {email: user.email}) | |
} else { | |
return done(null, false) | |
} | |
} catch (error) { | |
console.error(error) | |
} | |
}) | |
module.exports = (passport) => { | |
passport.use(jwtStrategy) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment