- Changed COOKIE_NAME from "peakSkills_userId" to "session_token" for better clarity. - Updated AuthClient to handle login and registration with new data structures. - Enhanced AuthWrapper to manage user sessions and display appropriate messages. - Added error handling in LoginForm and RegisterForm for better user feedback. - Refactored user service methods to streamline user creation and verification processes.
35 lines
1006 B
TypeScript
35 lines
1006 B
TypeScript
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();
|
|
|
|
let userProfile = null;
|
|
|
|
if (userUuid) {
|
|
// Si l'utilisateur est connecté, récupérer son profil côté serveur
|
|
userProfile = await userService.getUserByUuid(userUuid);
|
|
}
|
|
|
|
// Si l'utilisateur n'est pas connecté, afficher le formulaire d'auth
|
|
return (
|
|
<LoginLayout>
|
|
<AuthWrapper teams={teams} initialUser={userProfile} />
|
|
</LoginLayout>
|
|
);
|
|
} catch (error) {
|
|
console.error("Error loading login page:", error);
|
|
return (
|
|
<LoginLayout>
|
|
<LoginLoading />
|
|
</LoginLayout>
|
|
);
|
|
}
|
|
}
|