17 lines
414 B
TypeScript
17 lines
414 B
TypeScript
import {
|
|
ExecutionContext,
|
|
Injectable,
|
|
ForbiddenException,
|
|
} from '@nestjs/common';
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
|
|
@Injectable()
|
|
export class JwtAuthGuard extends AuthGuard('jwt') {
|
|
handleRequest(err: any, user: any, info: any, context: ExecutionContext) {
|
|
if (err || !user) {
|
|
throw new ForbiddenException('Access denied: token inválido o ausente');
|
|
}
|
|
return user;
|
|
}
|
|
}
|