feat: assert user is member of workspace for board routes
This commit is contained in:
22
packages/api/src/utils/auth.ts
Normal file
22
packages/api/src/utils/auth.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
import type { dbClient } from "@kan/db/client";
|
||||
import * as workspaceRepo from "@kan/db/repository/workspace.repo";
|
||||
|
||||
export async function assertUserInWorkspace(
|
||||
db: dbClient,
|
||||
userId: string,
|
||||
workspaceId: number,
|
||||
) {
|
||||
const isMember = await workspaceRepo.isUserInWorkspace(
|
||||
db,
|
||||
userId,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
if (!isMember)
|
||||
throw new TRPCError({
|
||||
message: `You do not have access to this workspace`,
|
||||
code: "FORBIDDEN",
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user