23 lines
626 B
TypeScript
23 lines
626 B
TypeScript
// eslint-disable-next-line import/named
|
|
import { ExtractJwt, Strategy as JwtStrategy } from 'passport-jwt';
|
|
|
|
import Auth from '../../../db/model/auth';
|
|
import { JWT_SECRET } from '../../../constants/env';
|
|
|
|
const opts = {
|
|
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
secretOrKey: JWT_SECRET,
|
|
issuer: process.env.JWT_ISSUER,
|
|
audience: process.env.JWT_AUDIENCE,
|
|
};
|
|
|
|
export default new JwtStrategy(opts, async (jwt_payload, done) => {
|
|
const auth = await Auth.findOne({ record: jwt_payload.sub }).catch();
|
|
|
|
if (auth) {
|
|
return done(null, auth);
|
|
}
|
|
|
|
return done(null, false);
|
|
});
|