File

apps/api/src/auth/strategies/jwt-refresh-token.strategy.ts

Extends

PassportStrategy( Strategy, 'jwt-refresh-token' )

Index

Methods

Constructor

constructor(authService: AuthService)
Parameters :
Name Type Optional
authService AuthService No

Methods

Async validate
validate(request: Request, payload: LoginWith2FAPayload)
Parameters :
Name Type Optional
request Request No
payload LoginWith2FAPayload No
Returns : unknown
import { Request } from 'express'
import { Injectable } from '@nestjs/common'
import { PassportStrategy } from '@nestjs/passport'
import { ExtractJwt, Strategy } from 'passport-jwt'
import { AuthService } from '../auth.service'
import { LoginWith2FAPayload } from '@isomera/interfaces'

@Injectable()
export class JwtRefreshTokenStrategy extends PassportStrategy(
  Strategy,
  'jwt-refresh-token'
) {
  constructor(private readonly authService: AuthService) {
    super({
      jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
      ignoreExpiration: false,
      secretOrKey: process.env.APP_SECRET,
      passReqToCallback: true
    })
  }

  async validate(request: Request, payload: LoginWith2FAPayload) {
    const user = await this.authService.getUserIfRefreshTokenMatched(
      payload.email,
      request.headers.authorization.split('Bearer ')[1]
    )

    return {
      ...user,
      isTwoFactorAuthenticated: payload.isTwoFactorAuthenticated
    }
  }
}

results matching ""

    No results matching ""