Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

645 B
Raw Blame
import { ExecutionContext, Injectable, Logger } from '@nestjs/common'
import { AuthGuard, IAuthGuard } from '@nestjs/passport'

@Injectable()
export class AuthTokenTwoFaGuard extends AuthGuard('tokenTwoFa') implements IAuthGuard {
  private readonly logger = new Logger(AuthTokenTwoFaGuard.name)

  handleRequest<TUser = any>(err: any, user: any, info: Error, ctx: ExecutionContext, status?: any): TUser {
    const req = this.getRequest(ctx)
    req.raw.user = user?.login || 'unauthorized'
    if (info) {
      this.logger.warn(`<${req.raw.user}> <${req.ip}> ${info}`)
    }
    return super.handleRequest(err, user, info, ctx, status)
  }
}