'use client'; import { useEffect, useState } from 'react'; import { useRouter } from 'next/navigation'; import { Loader2 } from 'lucide-react'; interface ShareLinkBootstrapProps { videoId: string; shareToken: string; } export function ShareLinkBootstrap({ videoId, shareToken }: ShareLinkBootstrapProps) { const router = useRouter(); const [error, setError] = useState(''); useEffect(() => { let isCancelled = false; async function establishSession() { try { const response = await fetch(`/watch/${videoId}/session`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ shareToken }), }); if (isCancelled) return; if (response.ok) { router.replace(`/watch/${videoId}`); router.refresh(); return; } const payload = (await response.json().catch(() => null)) as { requiresPassword?: boolean; error?: string; } | null; if (payload?.requiresPassword) { router.replace(`/watch/${videoId}?unlock=1`); return; } setError(payload?.error || 'Invalid or expired share link'); } catch { if (!isCancelled) { setError('Failed to open share link'); } } } void establishSession(); return () => { isCancelled = true; }; }, [router, shareToken, videoId]); return (

Opening shared video

{error || 'Verifying link access...'}

); }