create account marche
This commit is contained in:
@@ -8,9 +8,18 @@ export const Login =() =>{
|
||||
const { keycloak } = useKeycloak();
|
||||
|
||||
useEffect(() => {
|
||||
const syncUser = async () => {
|
||||
const syncAndLoadUser = async () => {
|
||||
if (keycloak.authenticated && keycloak.token) {
|
||||
console.log("Attempting to sync user with backend...");
|
||||
const tokenParsed = keycloak.tokenParsed;
|
||||
setUser({
|
||||
id: 0,
|
||||
keycloakId: tokenParsed!.sub!,
|
||||
email: tokenParsed?.email || "",
|
||||
nom: tokenParsed?.family_name || "",
|
||||
prenom: tokenParsed?.given_name || "",
|
||||
role: "athlete",
|
||||
sessions: []
|
||||
});
|
||||
try {
|
||||
const response = await fetch("http://localhost:8081/api/users/sync", {
|
||||
method: "POST",
|
||||
@@ -26,36 +35,8 @@ export const Login =() =>{
|
||||
}
|
||||
};
|
||||
|
||||
syncUser();
|
||||
}, [keycloak.authenticated, keycloak.token]);
|
||||
|
||||
useEffect(() => {
|
||||
if (keycloak.authenticated && keycloak.token) {
|
||||
fetch("http://localhost:8081/api/users/sync", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${keycloak.token}`,
|
||||
},
|
||||
})
|
||||
.then(res => console.log("Sync response status:", res.status))
|
||||
.catch(err => console.error("Sync error:", err));;
|
||||
}
|
||||
}, [keycloak.authenticated]);
|
||||
|
||||
useEffect(() => {
|
||||
if (keycloak.authenticated) {
|
||||
const tokenParsed = keycloak.tokenParsed;
|
||||
setUser({
|
||||
id: 0,
|
||||
keycloakId: tokenParsed!.sub!,
|
||||
email: tokenParsed?.email,
|
||||
nom: tokenParsed?.family_name,
|
||||
prenom: tokenParsed?.given_name,
|
||||
role: "athlete",
|
||||
sessions: []
|
||||
});
|
||||
}
|
||||
}, [keycloak.authenticated]);
|
||||
syncAndLoadUser();
|
||||
}, [keycloak.authenticated, keycloak.token, setUser]);
|
||||
|
||||
|
||||
function handleLogin(): void {
|
||||
|
||||
@@ -16,7 +16,7 @@ import { unescapeLeadingUnderscores } from "typescript";
|
||||
console.log(user.nom);
|
||||
console.log(user.prenom);
|
||||
console.log(user.email);
|
||||
if (user.role === "Athlete") return null;
|
||||
if (user.role === "athlete") return null;
|
||||
|
||||
|
||||
const athleteMap: Map<number, Athlete> = new Map();
|
||||
@@ -82,7 +82,7 @@ import { unescapeLeadingUnderscores } from "typescript";
|
||||
}}>
|
||||
<option value="athletes">Athlètes</option>
|
||||
<option value="activites">Activités</option>
|
||||
{user.role === "Admin" && <option value="coachs"> Coachs</option>}
|
||||
{user.role === "admin" && <option value="coachs"> Coachs</option>}
|
||||
<option value="sessions"> Sessions</option>
|
||||
<option value="lignes"> Lignes</option>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user