mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2025-12-17 05:09:26 +00:00
auth in progress
This commit is contained in:
27
src/modules/auth/strategies/refresh-token.strategy.ts
Normal file
27
src/modules/auth/strategies/refresh-token.strategy.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
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 }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user