'use client'; import { useState, useEffect, Suspense } from 'react'; import { useRouter, useSearchParams } from 'next/navigation'; import { useAuth } from '@/lib/auth-context'; import { invitationsApi } from '@/lib/api'; import { Button } from '@/components/ui/button'; function LoginForm() { const router = useRouter(); const searchParams = useSearchParams(); const inviteToken = searchParams.get('invite_token'); const { login, acceptedProjects, clearAcceptedProjects } = useAuth(); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const [justJoined, setJustJoined] = useState(false); // Pre-fill email if coming from invite link useEffect(() => { if (inviteToken) { invitationsApi.verify(inviteToken) .then(({ invitation }) => { if (!email) setEmail(invitation.email); }) .catch(() => {}); } }, [inviteToken]); // eslint-disable-line react-hooks/exhaustive-deps useEffect(() => { if (acceptedProjects.length > 0 && !justJoined) { setJustJoined(true); } }, [acceptedProjects, justJoined]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setLoading(true); try { await login(email, password); if (inviteToken) { router.push(`/invite/${inviteToken}`); } else { router.push('/projects'); } } catch (err: unknown) { setError(err instanceof Error ? err.message : 'Invalid email or password'); } finally { setLoading(false); } }; const handleGoToProject = (projectId: string) => { clearAcceptedProjects(); router.push(`/projects/${projectId}`); }; return (
You're now a member of:
{acceptedProjects.map(p => ( ))}Sign in to your workspace
No account yet?{' '} Create workspace
Demo: admin@vidreview.local {' / '} admin123
© 2026 VidReview — Video collaboration for creative teams