39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { redirect } from "next/navigation";
|
|
import { TeamsService, userService } from "@/services";
|
|
import { AuthService } from "@/services";
|
|
import { LoginLayout, AuthWrapper, LoginLoading } from "@/components/login";
|
|
|
|
export default async function LoginPage() {
|
|
try {
|
|
// Charger les équipes côté serveur
|
|
const teams = await TeamsService.getTeams();
|
|
|
|
// Vérifier si l'utilisateur est déjà connecté
|
|
const userUuid = await AuthService.getUserUuidFromCookie();
|
|
|
|
if (userUuid) {
|
|
// Si l'utilisateur est connecté, récupérer son profil côté serveur
|
|
const userProfile = await userService.getUserByUuid(userUuid);
|
|
|
|
if (userProfile) {
|
|
// Rediriger vers l'accueil si déjà connecté
|
|
redirect("/");
|
|
}
|
|
}
|
|
|
|
// Si l'utilisateur n'est pas connecté, afficher le formulaire d'auth
|
|
return (
|
|
<LoginLayout>
|
|
<AuthWrapper teams={teams} />
|
|
</LoginLayout>
|
|
);
|
|
} catch (error) {
|
|
console.error("Error loading login page:", error);
|
|
return (
|
|
<LoginLayout>
|
|
<LoginLoading />
|
|
</LoginLayout>
|
|
);
|
|
}
|
|
}
|