Skip to content

Instantly share code, notes, and snippets.

@kianaditya
Last active June 29, 2020 14:03
Show Gist options
  • Save kianaditya/b1482b5f85d89b683af91a06adec27c3 to your computer and use it in GitHub Desktop.
Save kianaditya/b1482b5f85d89b683af91a06adec27c3 to your computer and use it in GitHub Desktop.
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