Ocelot-Social/src/jwt/strategy.js
Grzegorz Leoniec 513de69bf9 some cleanup
2018-10-19 12:29:52 +02:00

30 lines
649 B
JavaScript

import { Strategy } from 'passport-jwt'
const cookieExtractor = (req) => {
var token = null
if (req && req.cookies) {
token = req.cookies['jwt']
}
return token
}
export default () => {
const options = {
jwtFromRequest: cookieExtractor,
secretOrKey: process.env.JWT_SECRET,
issuer: process.env.GRAPHQL_URI,
audience: process.env.CLIENT_URI
}
return new Strategy(options,
(JWTPayload, next) => {
// usually this would be a database call:
// var user = users[_.findIndex(users, {id: JWTPayload.id})]
if (true) {
next(null, {})
} else {
next(null, false)
}
})
}