fix: jwt-auth.guard handleRequest wrong signature causing null.switchToHttp crash
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Injectable, CanActivate, ExecutionContext, Logger } from '@nestjs/common';
|
||||
import { Injectable, CanActivate, ExecutionContext, Logger, UnauthorizedException } from '@nestjs/common';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Reflector } from '@nestjs/core';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
@@ -21,15 +21,14 @@ export class JwtAuthGuard extends AuthGuard('jwt') {
|
||||
return super.canActivate(context);
|
||||
}
|
||||
|
||||
// Add logging for user ID in the JWT authentication guard
|
||||
handleRequest(context: ExecutionContext, next: Function) {
|
||||
const request = context.switchToHttp().getRequest();
|
||||
const user = request.user;
|
||||
|
||||
if (user) {
|
||||
this.logger.log(`User ID: ${user.userId}, Username: ${user.username}`);
|
||||
// Log authenticated user ID for diagnostics
|
||||
handleRequest<TUser = any>(err: any, user: TUser, info: any): TUser {
|
||||
if (err || !user) {
|
||||
throw err || new UnauthorizedException();
|
||||
}
|
||||
|
||||
return next();
|
||||
if (user) {
|
||||
this.logger.log(`Authenticated user ID: ${(user as any).userId}`);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user