"use client"; import React, { useState } from 'react'; import { useRouter } from 'next/navigation'; import Link from 'next/link'; import { useUser } from '../../components/UserProvider'; const LoginPage = () => { const { settings, login } = useUser(); const siteName = settings?.siteName || "Afrohub"; const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const router = useRouter(); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(''); try { const res = await fetch('/api/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, password }), }); const data = await res.json(); if (!res.ok) { throw new Error(data.error || 'Erreur lors de la connexion'); } // Real login with user data from DB login(data.user); router.push('/dashboard'); } catch (err: any) { setError(err.message); } finally { setLoading(false); } }; return (
Ou créez votre compte entreprise pour 1€