diff --git a/packages/api/src/routers/card.ts b/packages/api/src/routers/card.ts index d3d9da3a..443aabc9 100644 --- a/packages/api/src/routers/card.ts +++ b/packages/api/src/routers/card.ts @@ -578,14 +578,6 @@ export const cardRouter = createTRPCRouter({ >(), ) .query(async ({ ctx, input }) => { - const userId = ctx.user?.id; - - if (!userId) - throw new TRPCError({ - message: `User not authenticated`, - code: "UNAUTHORIZED", - }); - const card = await cardRepo.getWorkspaceAndCardIdByCardPublicId( ctx.db, input.cardPublicId, @@ -597,7 +589,17 @@ export const cardRouter = createTRPCRouter({ code: "NOT_FOUND", }); - await assertUserInWorkspace(ctx.db, userId, card.workspaceId); + if (card.workspaceVisibility === "private") { + const userId = ctx.user?.id; + + if (!userId) + throw new TRPCError({ + message: `User not authenticated`, + code: "UNAUTHORIZED", + }); + + await assertUserInWorkspace(ctx.db, userId, card.workspaceId); + } const result = await cardRepo.getWithListAndMembersByPublicId( ctx.db, diff --git a/packages/db/src/repository/card.repo.ts b/packages/db/src/repository/card.repo.ts index 790dc4ba..32948552 100644 --- a/packages/db/src/repository/card.repo.ts +++ b/packages/db/src/repository/card.repo.ts @@ -731,6 +731,7 @@ export const getWorkspaceAndCardIdByCardPublicId = async ( board: { columns: { workspaceId: true, + visibility: true, }, }, }, @@ -742,6 +743,7 @@ export const getWorkspaceAndCardIdByCardPublicId = async ( ? { id: result.id, workspaceId: result.list.board.workspaceId, + workspaceVisibility: result.list.board.visibility, } : null; };