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 {
|
||||
|
||||
Reference in New Issue
Block a user