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 ( +
+
+
+

+ MatériauxDestock +

+

Interface de gestion

+
+ +
+ {error && ( +
+ {error} +
+ )} + +
+ + setEmail(e.target.value)} + required + autoComplete="email" + className="w-full bg-slate-800 border border-slate-700 rounded-lg px-3 py-2.5 text-sm text-white placeholder-slate-500 focus:outline-none focus:border-indigo-500 transition-colors" + placeholder="vous@example.com" + /> +
+ +
+ + setPassword(e.target.value)} + required + autoComplete="current-password" + className="w-full bg-slate-800 border border-slate-700 rounded-lg px-3 py-2.5 text-sm text-white placeholder-slate-500 focus:outline-none focus:border-indigo-500 transition-colors" + placeholder="••••••••" + /> +
+ + +
+
+
+ ) +} diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 6324e93..2e5ac88 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,6 +1,7 @@ import type { Metadata } from 'next' import { Inter } from 'next/font/google' import './globals.css' +import { SessionProvider } from '@/components/providers/SessionProvider' const inter = Inter({ subsets: ['latin'] }) @@ -12,7 +13,9 @@ export const metadata: Metadata = { export default function RootLayout({ children }: { children: React.ReactNode }) { return ( - {children} + + {children} + ) } diff --git a/src/components/providers/SessionProvider.tsx b/src/components/providers/SessionProvider.tsx new file mode 100644 index 0000000..060ad89 --- /dev/null +++ b/src/components/providers/SessionProvider.tsx @@ -0,0 +1,6 @@ +'use client' +import { SessionProvider as NextAuthSessionProvider } from 'next-auth/react' + +export function SessionProvider({ children }: { children: React.ReactNode }) { + return {children} +}