getUser
This commit is contained in:
@@ -2,6 +2,7 @@ import axios from "axios";
|
|||||||
|
|
||||||
import keycloak from "./keycloak";
|
import keycloak from "./keycloak";
|
||||||
import { get } from "http";
|
import { get } from "http";
|
||||||
|
import { AdminDTO, AthleteDTO, CoachDTO } from "./classesDTO";
|
||||||
|
|
||||||
|
|
||||||
const api = axios.create({
|
const api = axios.create({
|
||||||
@@ -37,7 +38,7 @@ export function clearAuthToken() {
|
|||||||
|
|
||||||
export const athleteService = {
|
export const athleteService = {
|
||||||
// controller is mounted at /athlete
|
// controller is mounted at /athlete
|
||||||
create: (data: any) => api.post("/athlete/create", data),
|
create: (data: any) => api.post<AthleteDTO>("/athlete/create", data),
|
||||||
getAll: () => api.get("/athlete/all"),
|
getAll: () => api.get("/athlete/all"),
|
||||||
getById: (id: number | string) => api.get(`/athlete/${id}`),
|
getById: (id: number | string) => api.get(`/athlete/${id}`),
|
||||||
getByKeycloakId: (keycloakId: string) => api.get(`/athlete/keycloak/${encodeURIComponent(keycloakId)}`),
|
getByKeycloakId: (keycloakId: string) => api.get(`/athlete/keycloak/${encodeURIComponent(keycloakId)}`),
|
||||||
@@ -81,7 +82,7 @@ export const sessionService = {
|
|||||||
|
|
||||||
export const coachService = {
|
export const coachService = {
|
||||||
// controller doesn't declare a class-level path consistently; support both common patterns
|
// controller doesn't declare a class-level path consistently; support both common patterns
|
||||||
create: (data: any) => api.post(`/coach/create`, data),
|
create: (data: any) => api.post<CoachDTO>(`/coach/create`, data),
|
||||||
getAll: () => api.get(`/coach/all`),
|
getAll: () => api.get(`/coach/all`),
|
||||||
getByKeycloakId: (id: number | string) => api.get(`/coach/${id}`),
|
getByKeycloakId: (id: number | string) => api.get(`/coach/${id}`),
|
||||||
update: (id: number | string, data: any) => api.put(`/coach/update/${id}`, data),
|
update: (id: number | string, data: any) => api.put(`/coach/update/${id}`, data),
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import api, { activiteService, sessionService } from "./api";
|
import api, { activiteService, athleteService, coachService, sessionService } from "./api";
|
||||||
import { Activite, Admin, Athlete, Coach, Session, User } from "./classes";
|
import { Activite, Admin, Athlete, Coach, Session, User } from "./classes";
|
||||||
import Keycloak from 'keycloak-js'
|
import Keycloak from 'keycloak-js'
|
||||||
import { AdminDTO, AthleteDTO, CoachDTO } from "./classesDTO";
|
import { AdminDTO, AthleteDTO, CoachDTO } from "./classesDTO";
|
||||||
@@ -20,17 +20,17 @@ export async function getUser(keycloak:Keycloak): Promise<User|null>{
|
|||||||
const roles = keycloak.tokenParsed?.realm_access?.roles
|
const roles = keycloak.tokenParsed?.realm_access?.roles
|
||||||
if(roles!=null){
|
if(roles!=null){
|
||||||
if(roles.includes("admin")){
|
if(roles.includes("admin")){
|
||||||
const response = await api.get<AdminDTO>(`/TODO`);
|
const response = await athleteService.create(keycloak.tokenParsed);
|
||||||
const admin = new Admin(response.data);
|
const admin = new Admin(response.data);
|
||||||
return admin;
|
return admin;
|
||||||
}
|
}
|
||||||
else if(roles.includes("coach")){
|
else if(roles.includes("coach")){
|
||||||
const response = await api.get<CoachDTO>(`/TODO`);
|
const response = await coachService.create(keycloak.tokenParsed);
|
||||||
const coach = new Coach(response.data);
|
const coach = new Coach(response.data);
|
||||||
return coach;
|
return coach;
|
||||||
}
|
}
|
||||||
else if(roles.includes("athletes")){
|
else if(roles.includes("athletes")){
|
||||||
const response = await api.get<AthleteDTO>(`/TODO`);
|
const response = await athleteService.create(keycloak.tokenParsed);
|
||||||
const athlete = new Athlete(response.data);
|
const athlete = new Athlete(response.data);
|
||||||
return athlete;
|
return athlete;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user