change in athlete and getkeycloak
This commit is contained in:
@@ -3,20 +3,42 @@ import { useEffect } from 'react';
|
||||
import { getUserTest, User } from '../classes';
|
||||
import { useLocalData } from '../context/useLocalData';
|
||||
|
||||
|
||||
|
||||
|
||||
export const Login =() =>{
|
||||
const {user,setUser} = useLocalData()
|
||||
const { keycloak } = useKeycloak();
|
||||
|
||||
useEffect(() => {
|
||||
if (keycloak.authenticated) {
|
||||
fetch("http://localhost:8080/api/athlete/create", {
|
||||
const syncUser = async () => {
|
||||
if (keycloak.authenticated && keycloak.token) {
|
||||
console.log("Attempting to sync user with backend...");
|
||||
try {
|
||||
const response = await fetch("http://localhost:8081/api/users/sync", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Authorization": `Bearer ${keycloak.token}`,
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
});
|
||||
console.log("Sync status:", response.status);
|
||||
} catch (error) {
|
||||
console.error("Sync fetch failed:", error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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]);
|
||||
|
||||
@@ -24,7 +46,8 @@ export const Login =() =>{
|
||||
if (keycloak.authenticated) {
|
||||
const tokenParsed = keycloak.tokenParsed;
|
||||
setUser({
|
||||
id: tokenParsed?.id,
|
||||
id: 0,
|
||||
keycloakId: tokenParsed!.sub!,
|
||||
email: tokenParsed?.email,
|
||||
nom: tokenParsed?.family_name,
|
||||
prenom: tokenParsed?.given_name,
|
||||
|
||||
Reference in New Issue
Block a user