diff --git a/src/app/(auth)/login/page.tsx b/src/app/(auth)/login/page.tsx new file mode 100644 index 0000000..e3a2f99 --- /dev/null +++ b/src/app/(auth)/login/page.tsx @@ -0,0 +1,97 @@ +'use client' +import { signIn } from 'next-auth/react' +import { useState, FormEvent } from 'react' +import { useRouter } from 'next/navigation' + +export default function LoginPage() { + const [email, setEmail] = useState('') + const [password, setPassword] = useState('') + const [error, setError] = useState('') + const [loading, setLoading] = useState(false) + const router = useRouter() + + async function handleSubmit(e: FormEvent) { + e.preventDefault() + setLoading(true) + setError('') + + const result = await signIn('credentials', { + email, + password, + redirect: false, + }) + + setLoading(false) + + if (result?.error === 'RATE_LIMITED') { + setError('Trop de tentatives. Réessayez dans 15 minutes.') + } else if (result?.error) { + setError('Email ou mot de passe incorrect.') + } else { + router.push('/') + router.refresh() + } + } + + return ( +
Interface de gestion
+