summaryrefslogtreecommitdiff
path: root/server/providers/guards/roles.guard.ts
diff options
context:
space:
mode:
authorJoseph Ditton <jditton.atomic@gmail.com>2021-12-03 14:46:44 -0700
committerJoseph Ditton <jditton.atomic@gmail.com>2021-12-03 14:46:44 -0700
commit95961c5a14d07c79ffae0f0f36b58ca7c3ea521b (patch)
tree7d20b3e6f44d54a4c1c24b07689bf5e036e104fc /server/providers/guards/roles.guard.ts
parent84b45cd6b11347e66437cd92dc20372d0abd6eb9 (diff)
downloadlocchat-95961c5a14d07c79ffae0f0f36b58ca7c3ea521b.tar.gz
locchat-95961c5a14d07c79ffae0f0f36b58ca7c3ea521b.zip
auth guard update
Diffstat (limited to 'server/providers/guards/roles.guard.ts')
-rw-r--r--server/providers/guards/roles.guard.ts11
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));
}
}