mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
30 lines
649 B
JavaScript
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)
|
|
}
|
|
})
|
|
}
|