mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-23 20:27:55 +00:00
19 lines
563 B
TypeScript
19 lines
563 B
TypeScript
import { RoleType } from '@app/common/constants/role.type.enum';
|
|
import { BadRequestException, UnauthorizedException } from '@nestjs/common';
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
|
|
export class SuperAdminRoleGuard extends AuthGuard('jwt') {
|
|
handleRequest(err, user) {
|
|
if (err || !user) {
|
|
throw err || new UnauthorizedException();
|
|
} else {
|
|
if (!(user.role.type === RoleType.SUPER_ADMIN)) {
|
|
throw new BadRequestException(
|
|
'Only super admin role can access this route',
|
|
);
|
|
}
|
|
}
|
|
return user;
|
|
}
|
|
}
|