import { useState } from 'react' import { useRouter } from 'next/router' import { signIn } from 'next-auth/react' export default function SignIn() { const [username, setUsername] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState('') const [loading, setLoading] = useState(false) const router = useRouter() const handleSubmit = async (e) => { e.preventDefault() setError('') setLoading(true) try { const result = await signIn('credentials', { redirect: false, callbackUrl: '/dashboard', username, password, }) if (result.error) { setError(result.error) } else if (result.status === 'ok') { router.push('/dashboard') } } catch (err) { setError('Authentication error') } finally { setLoading(false) } } return (