create-nest-template-malahimdev
Version:
Scaffolds a NestJS template with Swagger, global pipes, exception filters, MongoDB connection and response helpers.
15 lines (12 loc) • 491 B
text/typescript
import { CanActivate, ExecutionContext, Injectable, UnauthorizedException } from '@nestjs/common';
()
export class JwtAuthGuard implements CanActivate {
canActivate(context: ExecutionContext): boolean {
const request = context.switchToHttp().getRequest();
const authHeader = request.headers.authorization;
if (!authHeader || authHeader !== 'Bearer my-secret-token') {
throw new UnauthorizedException('Invalid or missing token');
}
return true;
}
}