Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

feat(api): add workspace access validation utility

Andrej Acevskiaeabf4cd5f5f
diff --git a/apps/api/src/utils/validate-workspace-access.ts b/apps/api/src/utils/validate-workspace-access.ts
new file mode 100644
index 000000000..8b0ef9325
--- /dev/null
+++ b/apps/api/src/utils/validate-workspace-access.ts
@@ -0,0 +1,31 @@
+import { and, eq } from "drizzle-orm";
+import { HTTPException } from "hono/http-exception";
+import db, { schema } from "../database";
+
+/**
+ * Validates that a user has access to a workspace
+ * @param userId - The user's ID
+ * @param workspaceId - The workspace ID to check
+ * @throws HTTPException with 403 if user doesn't have access
+ */
+export async function validateWorkspaceAccess(
+ userId: string,
+ workspaceId: string,
+): Promise<void> {
+ const membership = await db
+ .select()
+ .from(schema.workspaceUserTable)
+ .where(
+ and(
+ eq(schema.workspaceUserTable.userId, userId),
+ eq(schema.workspaceUserTable.workspaceId, workspaceId),
+ ),
+ )
+ .limit(1);
+
+ if (membership.length === 0) {
+ throw new HTTPException(403, {
+ message: "You don't have access to this workspace",
+ });
+ }
+}