diff --git a/src/api/EntryPoint.ts b/src/api/EntryPoint.ts deleted file mode 100644 index c3ef802d60c206998c340867a068aa11769eff33..0000000000000000000000000000000000000000 --- a/src/api/EntryPoint.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Contains server api entrypoints. - * Every server api call must be defined here and then used in the code. - */ -export enum EntryPoint { - login = '/api/web/login', - seniors = 'api/web/seniors/', -} diff --git a/src/api/fetchCookie.ts b/src/api/fetchCookie.ts index b2b27209425b04987e927d8e33f71f8403e17c06..d531ad2c1a0ae6fd2074300c38dfcc951c8f87f1 100644 --- a/src/api/fetchCookie.ts +++ b/src/api/fetchCookie.ts @@ -1,16 +1,9 @@ import axios from 'axios'; /** - * - * Ask and set csrf cookie to server. - * @param setIsCookieFetched function to set the state isCookieFetched. - * @returns null + * Call for csrf cookie. This cookie is the user session identifier and + * must be sent during the login process. + * @returns csrf cookie */ -export const fetchCookie = async ( - setIsCookieFetched: React.Dispatch<React.SetStateAction<string>>, -): Promise<unknown> => { - const response = await axios('/api/web/csrf'); - setIsCookieFetched(response.data.token); - localStorage.setItem('COOKIE', response.data.token); - return null; -}; +export const fetchCookie = async (): Promise<string> => + axios('/api/web/csrf').then((res) => res.data.token); diff --git a/src/api/getRole.ts b/src/api/getRole.ts index a20d30444cd9c69f720a6f1b72f9317268cdc046..cb06049debab84ddb437b373319a1c910d611ccc 100644 --- a/src/api/getRole.ts +++ b/src/api/getRole.ts @@ -1,12 +1,9 @@ import axios from 'axios'; -import { AuthContext } from 'components/AuthUser/AuthContext'; -import { useContext } from 'react'; -export const getRole = async ( - setRole: React.Dispatch<React.SetStateAction<string>>, -): Promise<void> => { - const response = await axios('/api/web/login/get_role').then( - (res) => res.data.role, - ); - setRole(response); -}; +/** + * Asks for the current set role. + * @returns empty if the role is not set or a name between those defined + * in {@see userRoles} + */ +export const getRole = async (): Promise<string> => + axios('/api/web/login/get_role').then((res) => res.data.role); diff --git a/src/api/isAuthenticated.ts b/src/api/isAuthenticated.ts index 1195e01ccfab49f4cc2581c749a61733a6d5e27a..041b4be81d010544d23c5515ef4ea15808f70aa4 100644 --- a/src/api/isAuthenticated.ts +++ b/src/api/isAuthenticated.ts @@ -1,5 +1,9 @@ import axios from 'axios'; +/** + * Ask the server if the user is authenticated. + * @returns true or false if the user is authenticated. + */ export const isAuthenticated = async (): Promise<boolean> => axios('/api/web/login/is_authenticated').then( (res) => res.data.is_authenticated,