Skip to content

Commit 356e359

Browse files
feat: allow public card access without authentication (#19)
1 parent 1698b74 commit 356e359

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

packages/api/src/routers/card.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -578,14 +578,6 @@ export const cardRouter = createTRPCRouter({
578578
>(),
579579
)
580580
.query(async ({ ctx, input }) => {
581-
const userId = ctx.user?.id;
582-
583-
if (!userId)
584-
throw new TRPCError({
585-
message: `User not authenticated`,
586-
code: "UNAUTHORIZED",
587-
});
588-
589581
const card = await cardRepo.getWorkspaceAndCardIdByCardPublicId(
590582
ctx.db,
591583
input.cardPublicId,
@@ -597,7 +589,17 @@ export const cardRouter = createTRPCRouter({
597589
code: "NOT_FOUND",
598590
});
599591

600-
await assertUserInWorkspace(ctx.db, userId, card.workspaceId);
592+
if (card.workspaceVisibility === "private") {
593+
const userId = ctx.user?.id;
594+
595+
if (!userId)
596+
throw new TRPCError({
597+
message: `User not authenticated`,
598+
code: "UNAUTHORIZED",
599+
});
600+
601+
await assertUserInWorkspace(ctx.db, userId, card.workspaceId);
602+
}
601603

602604
const result = await cardRepo.getWithListAndMembersByPublicId(
603605
ctx.db,

packages/db/src/repository/card.repo.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ export const getWorkspaceAndCardIdByCardPublicId = async (
731731
board: {
732732
columns: {
733733
workspaceId: true,
734+
visibility: true,
734735
},
735736
},
736737
},
@@ -742,6 +743,7 @@ export const getWorkspaceAndCardIdByCardPublicId = async (
742743
? {
743744
id: result.id,
744745
workspaceId: result.list.board.workspaceId,
746+
workspaceVisibility: result.list.board.visibility,
745747
}
746748
: null;
747749
};

0 commit comments

Comments
 (0)