Adiciona primeiros Guards de autenticacao

This commit is contained in:
LeoMortari
2025-09-11 18:46:59 -03:00
parent ee1e3bd7f8
commit 13b41d2f52
7 changed files with 83 additions and 18 deletions

View File

@@ -0,0 +1,18 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import type { JwtPayload } from './keycloak.strategy';
@Injectable()
export class KeycloakAuthGuard extends AuthGuard('jwt') {
handleRequest(err: unknown, user: JwtPayload): JwtPayload {
if (err || !user) {
if (err instanceof UnauthorizedException) {
throw err;
}
throw new UnauthorizedException('Usuário não autenticado');
}
return user;
}
}