correction login

This commit is contained in:
trochas
2026-01-09 10:46:41 +01:00
parent 34f37b99cc
commit b4200cc029
2 changed files with 69 additions and 56 deletions

View File

@@ -15,28 +15,46 @@ export function delay(ms: number): Promise<void> {
/*
retourne l'utilisateur lié à l'identifiant keyloack
*/
export async function getUser(keycloak:Keycloak): Promise<User|null>{
export async function loginOrRegister(keycloak:Keycloak): Promise<User|null>{
try {
const roles = keycloak.tokenParsed?.realm_access?.roles
if(roles!=null){
if(roles.includes("admin")){
const response = await athleteService.create(keycloak.tokenParsed);
const admin = new Admin(response.data);
return admin;
if(keycloak.tokenParsed!=null){
const roles = keycloak.tokenParsed?.realm_access?.roles
if(roles!=null){
if(roles.includes("admin")){
const id = keycloak.tokenParsed?.sub;
if(id!=null){
const response = await athleteService.getByKeycloakId(id);
const admin = new Admin(response.data);
return admin;
}
}
else if(roles.includes("coach")){
const id = keycloak.tokenParsed?.sub;
if(id!=null){
const response = await coachService.getByKeycloakId(id);
const coach = new Coach(response.data);
return coach;
}
}
else if(roles.includes("athlete")){
console.error("role = Athlete");
const newAthlete: Athlete = new Athlete();
newAthlete.keycloakId = keycloak.tokenParsed.sub || "";
newAthlete.email = keycloak.tokenParsed.email || "";
newAthlete.nom = keycloak.tokenParsed.family_name || "";
newAthlete.prenom = keycloak.tokenParsed.given_name || "";
const response = await athleteService.create(newAthlete.toDTO());
console.log(response);
const athlete = new Athlete(response.data);
console.log(athlete);
return athlete;
}
else console.error("Error : role inconnu");
}
else if(roles.includes("coach")){
const response = await coachService.create(keycloak.tokenParsed);
const coach = new Coach(response.data);
return coach;
}
else if(roles.includes("athletes")){
const response = await athleteService.create(keycloak.tokenParsed);
const athlete = new Athlete(response.data);
return athlete;
}
console.error("Error roles inconnu");
else console.error("Error : role null");
}
else console.error("Error : token Keylcoak null");
console.error("Error : pendant la récupération de l'User");
return null;
}
catch (error) {