From 0f58a9fda4385c2b7a57f93c4278bda52fbcfd27 Mon Sep 17 00:00:00 2001 From: MarconLP <13001502+MarconLP@users.noreply.github.com> Date: Sun, 23 Apr 2023 15:26:51 +0200 Subject: [PATCH] fix users without session cannot view shared videos --- src/server/api/routers/video.ts | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/server/api/routers/video.ts b/src/server/api/routers/video.ts index 18f260b..913f7e2 100644 --- a/src/server/api/routers/video.ts +++ b/src/server/api/routers/video.ts @@ -65,24 +65,26 @@ export const videoRouter = createTRPCRouter({ throw new TRPCError({ code: "NOT_FOUND" }); } - if (!session || (video.userId !== session?.user.id && !video.sharing)) { + if (video.userId !== session?.user.id && !video.sharing) { throw new TRPCError({ code: "FORBIDDEN" }); } - posthog.capture({ - distinctId: session.user.id, - event: "viewing video", - properties: { - videoId: video.id, - videoCreatedAt: video.createdAt, - videoUpdatedAt: video.updatedAt, - videoUser: video.user.id, - videoSharing: video.sharing, - videoDeleteAfterLinkExpires: video.delete_after_link_expires, - videoShareLinkExpiresAt: video.shareLinkExpiresAt, - }, - }); - void posthog.shutdownAsync(); + if (session) { + posthog.capture({ + distinctId: session.user.id, + event: "viewing video", + properties: { + videoId: video.id, + videoCreatedAt: video.createdAt, + videoUpdatedAt: video.updatedAt, + videoUser: video.user.id, + videoSharing: video.sharing, + videoDeleteAfterLinkExpires: video.delete_after_link_expires, + videoShareLinkExpiresAt: video.shareLinkExpiresAt, + }, + }); + void posthog.shutdownAsync(); + } const getObjectCommand = new GetObjectCommand({ Bucket: env.AWS_BUCKET_NAME,