'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import Link from 'next/link'; import { Lock, Loader2 } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; interface ShareLinkUnlockProps { videoId: string; } export function ShareLinkUnlock({ videoId }: ShareLinkUnlockProps) { const router = useRouter(); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); const submitPassword = async () => { if (!password.trim()) return; setIsSubmitting(true); setError(''); try { const response = await fetch(`/watch/${videoId}/session`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ password }), }); if (!response.ok) { const payload = (await response.json().catch(() => null)) as { error?: string } | null; setError(payload?.error || 'Invalid password'); return; } router.replace(`/watch/${videoId}`); router.refresh(); } catch { setError('Failed to verify password'); } finally { setIsSubmitting(false); } }; return (
Enter the password to continue to the shared video.
{error}
}Or{' '} sign in {' '} with your account