mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2026-01-24 21:02:07 +00:00
resend email in progress
This commit is contained in:
34
src/modules/auth/strategies/jwt-refresh.strategy.ts
Normal file
34
src/modules/auth/strategies/jwt-refresh.strategy.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Inject, Injectable } from '@nestjs/common'
|
||||
import { PassportStrategy } from '@nestjs/passport'
|
||||
import { Strategy } from 'passport-jwt'
|
||||
import { UsersService } from '../../users/services/users.service'
|
||||
import { AppSettings } from '../../../settings/app-settings'
|
||||
import { Request } from 'express'
|
||||
|
||||
const cookieExtractor = function (req: Request) {
|
||||
console.log(req.cookies)
|
||||
let token = null
|
||||
if (req && req.cookies) {
|
||||
token = req.cookies['refreshToken']
|
||||
}
|
||||
console.log(token)
|
||||
return token
|
||||
}
|
||||
// ...
|
||||
@Injectable()
|
||||
export class JwtRefreshStrategy extends PassportStrategy(Strategy, 'jwt-refresh') {
|
||||
constructor(
|
||||
@Inject(AppSettings.name) private readonly appSettings: AppSettings,
|
||||
private userService: UsersService
|
||||
) {
|
||||
super({
|
||||
jwtFromRequest: cookieExtractor,
|
||||
ignoreExpiration: true,
|
||||
secretOrKey: appSettings.auth.REFRESH_JWT_SECRET_KEY,
|
||||
})
|
||||
}
|
||||
|
||||
async validate(payload: any) {
|
||||
return this.userService.getUserById(payload.userId)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user