introduce the jwt strategy

This commit is contained in:
Sven Czarnian
2022-11-03 01:09:20 +01:00
parent 0913c46057
commit 0827ccd1b1

View File

@@ -0,0 +1,19 @@
import { PassportStrategy } from '@nestjs/passport';
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { ExtractJwt, Strategy } from 'passport-jwt';
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(config: ConfigService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: config.get<string>('server.jwt-secret'),
});
}
async validate(payload: any) {
return { userId: payload.sub, vatsimId: payload.vatsimId };
}
}