Skip to content
Snippets Groups Projects
Verified Commit eff6ab95 authored by Defendi Alberto's avatar Defendi Alberto
Browse files

Simplify calls to return only value.

The passed react state setter is removed.
parent 79e4f41d
No related branches found
No related tags found
2 merge requests!56Refined auth flow and new website pages.,!44New route type (RestrictedRoute) and better api calls.
/**
* 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/',
}
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);
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);
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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment