change in athlete and getkeycloak
This commit is contained in:
@@ -11,7 +11,7 @@ import EdtCoach from './components/edt_coach'
|
||||
import { Coach } from "./classes";
|
||||
import RessourcePanel from './components/ressourcePanel';
|
||||
import TestAPI from './components/test_api';
|
||||
|
||||
import EdtAthlete from './components/edt_athlete';
|
||||
// Test
|
||||
const testCoach = new Coach();
|
||||
testCoach.id = 1;
|
||||
@@ -36,7 +36,7 @@ function App() {
|
||||
<RessourcePanel/>
|
||||
<EDT/>
|
||||
<CreateSession/>
|
||||
|
||||
<EdtAthlete/>
|
||||
<TestAPI/>
|
||||
</div>
|
||||
</LocalDataProvider>
|
||||
|
||||
@@ -3,6 +3,7 @@ export type Role = "Admin" | "Athlete" | "Coach";
|
||||
|
||||
export class User{
|
||||
id!: number;
|
||||
keycloakId!: String;
|
||||
nom!: String;
|
||||
prenom!:String;
|
||||
sessions: Session[] = []; //nb: Admin liaison non symétrique /!\
|
||||
@@ -19,21 +20,17 @@ export class Ligne{
|
||||
|
||||
export class Admin extends User{
|
||||
role!: Role;
|
||||
|
||||
}
|
||||
|
||||
export class Athlete extends User{
|
||||
nom!: String;
|
||||
groupe!: Groupe;
|
||||
role!: Role;
|
||||
|
||||
|
||||
}
|
||||
|
||||
export class Coach extends User{
|
||||
nom!: String;
|
||||
role!: Role;
|
||||
|
||||
}
|
||||
|
||||
export class Session{
|
||||
|
||||
@@ -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