'use client' import { useState } from 'react' import { useRouter, useSearchParams } from 'next/navigation' import { signIn } from 'next-auth/react' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from '@/components/ui/card' export default function LoginPage() { const router = useRouter() const searchParams = useSearchParams() const callbackUrl = searchParams.get('callbackUrl') || '/' const error = searchParams.get('error') const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [userType, setUserType] = useState<'customer' | 'staff'>('staff') const [isLoading, setIsLoading] = useState(false) const [loginError, setLoginError] = useState(null) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setIsLoading(true) setLoginError(null) try { const result = await signIn('credentials', { email, password, userType, redirect: false, callbackUrl, }) if (result?.error) { setLoginError(result.error) } else if (result?.ok) { router.push(userType === 'staff' ? '/admin' : '/') router.refresh() } } catch { setLoginError('An unexpected error occurred') } finally { setIsLoading(false) } } return (
LetsBe Hub Sign in to your account
{(error || loginError) && (
{error === 'CredentialsSignin' ? 'Invalid email or password' : loginError || error}
)}
setEmail(e.target.value)} required autoComplete="email" />
setPassword(e.target.value)} required autoComplete="current-password" />
) }