create account marche

This commit is contained in:
tuanvu
2026-01-08 13:32:53 +01:00
parent a3cf9b821a
commit 85daf4647a
4 changed files with 64 additions and 35 deletions

View File

@@ -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 {