21 lines
624 B
TypeScript
21 lines
624 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import { PassportStrategy } from '@nestjs/passport';
|
|
import { ExtractJwt, Strategy } from 'passport-jwt';
|
|
import { JwtPayload } from '@tower/types';
|
|
|
|
@Injectable()
|
|
export class JwtStrategy extends PassportStrategy(Strategy) {
|
|
constructor(config: ConfigService) {
|
|
super({
|
|
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
ignoreExpiration: false,
|
|
secretOrKey: config.get<string>('JWT_SECRET') ?? '',
|
|
});
|
|
}
|
|
|
|
async validate(payload: JwtPayload): Promise<JwtPayload> {
|
|
return payload;
|
|
}
|
|
}
|