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'; import axios from 'axios';
/** /**
* * Call for csrf cookie. This cookie is the user session identifier and
* Ask and set csrf cookie to server. * must be sent during the login process.
* @param setIsCookieFetched function to set the state isCookieFetched. * @returns csrf cookie
* @returns null
*/ */
export const fetchCookie = async ( export const fetchCookie = async (): Promise<string> =>
setIsCookieFetched: React.Dispatch<React.SetStateAction<string>>, axios('/api/web/csrf').then((res) => res.data.token);
): Promise<unknown> => {
const response = await axios('/api/web/csrf');
setIsCookieFetched(response.data.token);
localStorage.setItem('COOKIE', response.data.token);
return null;
};
import axios from 'axios'; import axios from 'axios';
import { AuthContext } from 'components/AuthUser/AuthContext';
import { useContext } from 'react';
export const getRole = async ( /**
setRole: React.Dispatch<React.SetStateAction<string>>, * Asks for the current set role.
): Promise<void> => { * @returns empty if the role is not set or a name between those defined
const response = await axios('/api/web/login/get_role').then( * in {@see userRoles}
(res) => res.data.role, */
); export const getRole = async (): Promise<string> =>
setRole(response); axios('/api/web/login/get_role').then((res) => res.data.role);
};
import axios from 'axios'; 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> => export const isAuthenticated = async (): Promise<boolean> =>
axios('/api/web/login/is_authenticated').then( axios('/api/web/login/is_authenticated').then(
(res) => res.data.is_authenticated, (res) => res.data.is_authenticated,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment