Skip to content

Commit 50fe211

Browse files
committed
use properly auth checks for getVideoStatus
1 parent 85c736d commit 50fe211

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

apps/web/actions/videos/get-status.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getCurrentUser } from "@cap/database/auth/session";
55
import { users, videos } from "@cap/database/schema";
66
import type { VideoMetadata } from "@cap/database/types";
77
import { eq } from "drizzle-orm";
8+
import { userHasAccessToVideo } from "@/utils/auth";
89
import { isAiGenerationEnabled } from "@/utils/flags";
910
import { transcribeVideo } from "../../lib/transcribe";
1011
import { generateAiMetadata } from "./generate-ai-metadata";
@@ -23,12 +24,8 @@ export interface VideoStatusResult {
2324

2425
export async function getVideoStatus(
2526
videoId: string,
26-
): Promise<VideoStatusResult> {
27-
const user = await getCurrentUser();
28-
29-
if (!user) {
30-
throw new Error("Authentication required");
31-
}
27+
): Promise<VideoStatusResult | { success: false; access: string }> {
28+
const userPromise = getCurrentUser();
3229

3330
if (!videoId) {
3431
throw new Error("Video ID not provided");
@@ -229,6 +226,9 @@ export async function getVideoStatus(
229226
}
230227
}
231228

229+
const access = await userHasAccessToVideo(userPromise, video);
230+
if (access !== "has-access") return { success: false, access };
231+
232232
return {
233233
transcriptionStatus:
234234
(video.transcriptionStatus as "PROCESSING" | "COMPLETE" | "ERROR") ||

apps/web/app/s/[videoId]/Share.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ const useVideoStatus = (
7777
return useQuery({
7878
queryKey: ["videoStatus", videoId],
7979
queryFn: async (): Promise<VideoStatusResult> => {
80-
return await getVideoStatus(videoId);
80+
const res = await getVideoStatus(videoId);
81+
if ("success" in res && res.success === false)
82+
throw new Error("Failed to fetch video status");
83+
return res as VideoStatusResult;
8184
},
8285
initialData: initialData
8386
? {

0 commit comments

Comments
 (0)