'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Alert, AlertDescription } from '@/components/ui/alert'; import Loader2 from 'lucide-react/dist/esm/icons/loader-2'; import Eye from 'lucide-react/dist/esm/icons/eye'; import EyeOff from 'lucide-react/dist/esm/icons/eye-off'; import { signInWithEmail } from '@/lib/supabase'; export function SignInForm() { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(''); const router = useRouter(); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setIsLoading(true); setError(''); try { const { data, error } = await signInWithEmail(email, password); if (error) { if (error.message.includes('Invalid login credentials')) { setError('Invalid email or password. Please try again.'); } else if (error.message.includes('Email not confirmed')) { setError('Please check your email and click the confirmation link before signing in.'); } else { setError(error.message); } return; } if (data.user) { const role = data.user.app_metadata?.role === 'admin' ? 'admin' : 'user'; router.push(role === 'admin' ? '/admin' : '/user'); router.refresh(); } } catch { setError('An unexpected error occurred. Please try again.'); } finally { setIsLoading(false); } }; return ( Welcome back Sign in to your account to continue

Admins are redirected to /admin, users to{' '} /user. Promote a user by setting{' '} app_metadata.role = "admin" in Supabase, then sign in again.

{error && ( {error} )}
setEmail(e.target.value)} required disabled={isLoading} className="border-futuristic" />
setPassword(e.target.value)} required disabled={isLoading} className="border-futuristic pr-10" />
Don't have an account?
); }