Files
flashcards-api/src/modules/auth/strategies/jwt.strategy.ts
2023-06-13 01:39:33 +02:00

20 lines
633 B
TypeScript

import { Inject, Injectable } from '@nestjs/common'
import { PassportStrategy } from '@nestjs/passport'
import { ExtractJwt, Strategy } from 'passport-jwt'
import { AppSettings } from '../../../settings/app-settings'
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(@Inject(AppSettings.name) private readonly appSettings: AppSettings) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: true,
secretOrKey: appSettings.auth.ACCESS_JWT_SECRET_KEY,
})
}
async validate(payload: any) {
return { userId: payload.userId }
}
}