mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2025-12-16 20:59:26 +00:00
28 lines
871 B
TypeScript
28 lines
871 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'
|
|
import { Request } from 'express'
|
|
|
|
type JwtPayload = {
|
|
userId: string
|
|
username: string
|
|
}
|
|
|
|
@Injectable()
|
|
export class RefreshTokenStrategy extends PassportStrategy(Strategy, 'jwt-refresh') {
|
|
constructor(@Inject(AppSettings.name) private readonly appSettings: AppSettings) {
|
|
super({
|
|
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
ignoreExpiration: false,
|
|
secretOrKey: appSettings.auth.ACCESS_JWT_SECRET_KEY,
|
|
passReqToCallback: true,
|
|
})
|
|
}
|
|
|
|
validate(req: Request, payload: any) {
|
|
const refreshToken = req.get('Authorization').replace('Bearer', '').trim()
|
|
return { ...payload, refreshToken }
|
|
}
|
|
}
|