canina/backend/src/auth/jwt-auth.guard.ts

13 lines
401 B
TypeScript

import { Injectable, UnauthorizedException } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
@Injectable()
export class JwtAuthGuard extends AuthGuard('jwt') {
handleRequest(err: any, user: any, info: any) {
if (err || !user) {
throw err || new UnauthorizedException('لطفا ابتدا وارد حساب کاربری خود شوید');
}
return user;
}
}