mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-25 16:57:55 +00:00
Remove USER role
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||
import { BadRequestException, UnauthorizedException } from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
|
||||
export class UserRoleGuard extends AuthGuard('jwt') {
|
||||
handleRequest(err, user) {
|
||||
if (err || !user) {
|
||||
throw err || new UnauthorizedException();
|
||||
} else {
|
||||
const isUserOrAdmin = user.roles.some(
|
||||
(role) =>
|
||||
role.type === RoleType.SUPER_ADMIN ||
|
||||
role.type === RoleType.ADMIN ||
|
||||
role.type === RoleType.USER,
|
||||
);
|
||||
if (!isUserOrAdmin) {
|
||||
throw new BadRequestException(
|
||||
'Only admin or user role can access this route',
|
||||
);
|
||||
}
|
||||
}
|
||||
return user;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user