middleware
This commit is contained in:
1 parent
3bffe61b42
commit
816a1607a1
6 files changed
+10
-8
No files matched your search
@@ -122,6 +122,10 @@ export const addUserContext = async (
|
||||
const orgId = req.user.orgId;
|
||||
const currentTeamId = req.headers["x-team-id"] as string;
|
||||
|
||||
if (!currentTeamId || String(currentTeamId).trim().length === 0) {
|
||||
throw new ApiError("X-Team-Id header required", 400);
|
||||
}
|
||||
|
||||
// Get user team IDs
|
||||
const teamIds = await getTeamIds(sub);
|
||||
|
||||
|
||||
@@ -32,12 +32,12 @@ const verifyTeamPermission = (resourceActions: string[]) => {
|
||||
const tokenizedUser = req.user;
|
||||
|
||||
if (!tokenizedUser) {
|
||||
return next(new ApiError("No user", 400));
|
||||
return next(new ApiError("User not authenticated", 401));
|
||||
}
|
||||
|
||||
const userId = tokenizedUser.sub;
|
||||
if (!userId) {
|
||||
return next(new ApiError("No user ID", 400));
|
||||
return next(new ApiError("User not authenticated", 401));
|
||||
}
|
||||
|
||||
const orgPermissions = tokenizedUser.roles?.orgRole?.permissions || [];
|
||||
@@ -58,7 +58,7 @@ const verifyOrgPermission = (resourceActions: string[]) => {
|
||||
const userContext = req.user;
|
||||
|
||||
if (!userContext) {
|
||||
return next(new ApiError("No user", 400));
|
||||
return next(new ApiError("User not authenticated", 401));
|
||||
}
|
||||
|
||||
const orgPermissions = userContext.roles?.orgRole?.permissions || [];
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import RoleRoutes from "./roles.js";
|
||||
|
||||
export { default as AuthRoutes } from "./auth.js";
|
||||
export { default as InviteRoutes } from "./invite.js";
|
||||
export { default as MaintenanceRoutes } from "./maintenance.js";
|
||||
|
||||
@@ -20,8 +20,8 @@ class InviteRoutes {
|
||||
"/",
|
||||
verifyToken,
|
||||
addUserContext,
|
||||
validateBody(inviteSchema),
|
||||
verifyOrgPermission([PERMISSIONS.invite.write]),
|
||||
validateBody(inviteSchema),
|
||||
this.controller.create
|
||||
);
|
||||
|
||||
|
||||
@@ -52,8 +52,8 @@ class MonitorRoutes {
|
||||
"/import",
|
||||
verifyToken,
|
||||
addUserContext,
|
||||
validateBody(monitorImportSchema),
|
||||
verifyTeamPermission([PERMISSIONS.monitors.write]),
|
||||
validateBody(monitorImportSchema),
|
||||
this.controller.import
|
||||
);
|
||||
|
||||
|
||||
@@ -73,8 +73,8 @@ class NotificationChannelRoutes {
|
||||
"/test",
|
||||
verifyToken,
|
||||
addUserContext,
|
||||
validateBody(notificationChannelSchema),
|
||||
verifyTeamPermission([PERMISSIONS.notifications.write]),
|
||||
validateBody(notificationChannelSchema),
|
||||
this.controller.test
|
||||
);
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user