mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2025-12-16 12:33:17 +00:00
20 lines
633 B
TypeScript
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 }
|
|
}
|
|
}
|