diff options
Diffstat (limited to 'server/providers/guards/roles.guard.ts')
-rw-r--r-- | server/providers/guards/roles.guard.ts | 11 |
1 files changed, 2 insertions, 9 deletions
diff --git a/server/providers/guards/roles.guard.ts b/server/providers/guards/roles.guard.ts index 3ecc392..17aa224 100644 --- a/server/providers/guards/roles.guard.ts +++ b/server/providers/guards/roles.guard.ts @@ -5,7 +5,7 @@ import { JwtBodyDto } from 'server/dto/jwt_body.dto'; import { RoleKey } from 'server/entities/role.entity'; import { RolesService } from '../services/roles.service'; import { UsersService } from '../services/users.service'; -import { some } from 'lodash'; +import { intersection, isEmpty } from 'lodash'; @Injectable() export class RolesGuard implements CanActivate { @@ -16,7 +16,6 @@ export class RolesGuard implements CanActivate { context.getHandler(), context.getClass(), ]); - console.log(requiredRoles); if (!requiredRoles) { return true; @@ -26,12 +25,6 @@ export class RolesGuard implements CanActivate { if (!jwtBody) return false; // unauthenticated users are not authorized - const user = await this.usersService.find(jwtBody.userId, ['userRoles']); - const roles = await this.rolesService.findByKey(...requiredRoles); - const roleMatches = user.userRoles.map((userRole) => { - return !!roles.find((role) => role.id === userRole.roleId); - }); - - return some(roleMatches); + return !isEmpty(intersection(jwtBody.roles, requiredRoles)); } } |