Files
clipperia-api/src/auth/keycloak-auth.guard.ts
2025-09-11 18:46:59 -03:00

19 lines
504 B
TypeScript

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;
}
}