Created
June 22, 2020 15:21
-
-
Save kianaditya/466db7fb9befbacb10d255425daf2332 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 salt = 'thisismysecretstringthelogngerthebetter' | |
const models = require('./models') | |
const passport = require('passport') | |
const options = { | |
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), // need to add token to header in tests | |
secretOrKey: salt | |
} | |
module.exports = (passport) => { | |
passport.use( | |
new Strategy(options, (payload, done) => { | |
models.Author.findOne({ where: { name: payload.name } }) | |
.then(user => { | |
//success, user is found | |
return done(null, { | |
id: user.id, | |
name: user.name | |
}) | |
}) | |
.catch(error => { | |
// failure, user is NOT found | |
console.error(error) | |
return done(null, false) | |
}) | |
}) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment