feat: allow public card access without authentication (#19)

This commit is contained in:
LovelessCodes
2025-06-05 07:05:03 +02:00
committed by GitHub
parent 1698b744e4
commit 356e35964b
2 changed files with 13 additions and 9 deletions

View File

@@ -578,14 +578,6 @@ export const cardRouter = createTRPCRouter({
>(), >(),
) )
.query(async ({ ctx, input }) => { .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( const card = await cardRepo.getWorkspaceAndCardIdByCardPublicId(
ctx.db, ctx.db,
input.cardPublicId, input.cardPublicId,
@@ -597,7 +589,17 @@ export const cardRouter = createTRPCRouter({
code: "NOT_FOUND", 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( const result = await cardRepo.getWithListAndMembersByPublicId(
ctx.db, ctx.db,

View File

@@ -731,6 +731,7 @@ export const getWorkspaceAndCardIdByCardPublicId = async (
board: { board: {
columns: { columns: {
workspaceId: true, workspaceId: true,
visibility: true,
}, },
}, },
}, },
@@ -742,6 +743,7 @@ export const getWorkspaceAndCardIdByCardPublicId = async (
? { ? {
id: result.id, id: result.id,
workspaceId: result.list.board.workspaceId, workspaceId: result.list.board.workspaceId,
workspaceVisibility: result.list.board.visibility,
} }
: null; : null;
}; };