47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { redirect } from "next/navigation";
|
|
import { TeamsService, userService } from "@/services";
|
|
import { AuthService } from "@/services";
|
|
import {
|
|
LoginLayout,
|
|
LoginFormWrapper,
|
|
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) {
|
|
// Passer le profil utilisateur pour permettre la modification
|
|
return (
|
|
<LoginLayout>
|
|
<LoginFormWrapper teams={teams} initialUser={userProfile} />
|
|
</LoginLayout>
|
|
);
|
|
}
|
|
}
|
|
|
|
// Si l'utilisateur n'est pas connecté, afficher le formulaire de connexion
|
|
return (
|
|
<LoginLayout>
|
|
<LoginFormWrapper teams={teams} />
|
|
</LoginLayout>
|
|
);
|
|
} catch (error) {
|
|
console.error("Error loading login page:", error);
|
|
return (
|
|
<LoginLayout>
|
|
<LoginLoading />
|
|
</LoginLayout>
|
|
);
|
|
}
|
|
}
|