"use client"; import { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import { ProfileForm } from "@/components/profile-form"; import { AuthService } from "@/lib/auth-utils"; import { UserProfile, Team } from "@/lib/types"; import { Code2 } from "lucide-react"; interface LoginPageProps {} export default function LoginPage({}: LoginPageProps) { const [teams, setTeams] = useState([]); const [loading, setLoading] = useState(true); const [authenticating, setAuthenticating] = useState(false); const router = useRouter(); useEffect(() => { async function initialize() { try { // Vérifier si l'utilisateur est déjà connecté const currentUser = await AuthService.getCurrentUser(); if (currentUser) { router.push("/"); return; } // Charger les équipes const teamsResponse = await fetch("/api/teams"); if (teamsResponse.ok) { const teamsData = await teamsResponse.json(); setTeams(teamsData); } } catch (error) { console.error("Error initializing login page:", error); } finally { setLoading(false); } } initialize(); }, [router]); const handleSubmit = async (profile: UserProfile) => { setAuthenticating(true); try { await AuthService.login(profile); router.push("/"); } catch (error) { console.error("Login failed:", error); // Vous pouvez ajouter une notification d'erreur ici } finally { setAuthenticating(false); } }; if (loading) { return (

Chargement...

); } return (
PeakSkills

Bienvenue sur PeakSkills

Évaluez vos compétences techniques et suivez votre progression

{authenticating && (

Connexion en cours...

)}
); }