more user role stuff

This commit is contained in:
Milo Schwartz
2024-11-09 23:59:19 -05:00
parent bb17d30c9e
commit 231e1d2e2d
32 changed files with 897 additions and 138 deletions

View File

@@ -12,7 +12,6 @@ export async function verifyOrgAccess(
) {
const userId = req.user!.userId;
const orgId = req.params.orgId;
let userOrg = req.userOrg;
if (!userId) {
return next(
@@ -27,17 +26,17 @@ export async function verifyOrgAccess(
}
try {
if (!userOrg) {
if (!req.userOrg) {
const userOrgRes = await db
.select()
.from(userOrgs)
.where(
and(eq(userOrgs.userId, userId), eq(userOrgs.orgId, orgId))
);
userOrg = userOrgRes[0];
req.userOrg = userOrgRes[0];
}
if (!userOrg) {
if (!req.userOrg) {
next(
createHttpError(
HttpCode.FORBIDDEN,
@@ -46,7 +45,7 @@ export async function verifyOrgAccess(
);
} else {
// User has access, attach the user's role to the request for potential future use
req.userOrgRoleId = userOrg.roleId;
req.userOrgRoleId = req.userOrg.roleId;
req.userOrgId = orgId;
return next();
}