Add logs
This commit is contained in:
@@ -7,18 +7,26 @@ import type { JwtPayload } from './keycloak.strategy';
|
||||
export class KeycloakAuthGuard extends AuthGuard('jwt') {
|
||||
private readonly logger = new Logger(KeycloakAuthGuard.name);
|
||||
|
||||
handleRequest<TUser = JwtPayload>(err: any, user: JwtPayload): TUser {
|
||||
this.logger.log('KeycloakAuthGuard.handleRequest');
|
||||
console.log(user);
|
||||
console.log(err);
|
||||
handleRequest<TUser = JwtPayload>(
|
||||
err: unknown,
|
||||
user: JwtPayload | false,
|
||||
info: unknown,
|
||||
context: import('@nestjs/common').ExecutionContext,
|
||||
): TUser {
|
||||
this.logger.log(`User: ${JSON.stringify(user)}`);
|
||||
this.logger.log(`Error: ${JSON.stringify(err)}`);
|
||||
this.logger.log(`Info: ${JSON.stringify(info)}`);
|
||||
|
||||
if (err || !user) {
|
||||
if (err instanceof UnauthorizedException) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
throw new UnauthorizedException('Usuário não autenticado');
|
||||
}
|
||||
|
||||
return user as unknown as TUser;
|
||||
const request = context.switchToHttp().getRequest<{ user?: JwtPayload }>();
|
||||
request.user = user;
|
||||
|
||||
return user as TUser;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user