fix middleware
This commit is contained in:
1 parent
c92c7fb9c1
commit
710d506de2
1 file changed
+5
-5
@@ -32,12 +32,12 @@ const verifyTeamPermission = (resourceActions: string[]) => {
|
|||||||
const tokenizedUser = req.user;
|
const tokenizedUser = req.user;
|
||||||
|
|
||||||
if (!tokenizedUser) {
|
if (!tokenizedUser) {
|
||||||
throw new ApiError("No user", 400);
|
return next(new ApiError("No user", 400));
|
||||||
}
|
}
|
||||||
|
|
||||||
const userId = tokenizedUser.sub;
|
const userId = tokenizedUser.sub;
|
||||||
if (!userId) {
|
if (!userId) {
|
||||||
throw new ApiError("No user ID", 400);
|
return next(new ApiError("No user ID", 400));
|
||||||
}
|
}
|
||||||
|
|
||||||
const orgPermissions = tokenizedUser.roles?.orgRole?.permissions || [];
|
const orgPermissions = tokenizedUser.roles?.orgRole?.permissions || [];
|
||||||
@@ -47,7 +47,7 @@ const verifyTeamPermission = (resourceActions: string[]) => {
|
|||||||
|
|
||||||
const allowed = hasPermission(allPermissions, resourceActions);
|
const allowed = hasPermission(allPermissions, resourceActions);
|
||||||
if (!allowed) {
|
if (!allowed) {
|
||||||
throw new ApiError("Insufficient permissions", 403);
|
return next(new ApiError("Insufficient permissions", 403));
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
@@ -58,13 +58,13 @@ const verifyOrgPermission = (resourceActions: string[]) => {
|
|||||||
const userContext = req.user;
|
const userContext = req.user;
|
||||||
|
|
||||||
if (!userContext) {
|
if (!userContext) {
|
||||||
throw new ApiError("No user", 400);
|
return next(new ApiError("No user", 400));
|
||||||
}
|
}
|
||||||
|
|
||||||
const orgPermissions = userContext.roles?.orgRole?.permissions || [];
|
const orgPermissions = userContext.roles?.orgRole?.permissions || [];
|
||||||
const allowed = hasPermission(orgPermissions, resourceActions);
|
const allowed = hasPermission(orgPermissions, resourceActions);
|
||||||
if (!allowed) {
|
if (!allowed) {
|
||||||
throw new ApiError("Insufficient permissions", 403);
|
return next(new ApiError("Insufficient permissions", 403));
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user