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

Reintegrate lost folder.

parent 42978cd9
No related branches found
No related tags found
2 merge requests!56Refined auth flow and new website pages.,!50Fix/authorization
import { isAuthenticated } from 'api/isAuthenticated';
import { useEffect, useState } from 'react';
/**
* Custom hook that uses the call is_authenticated.
* {@link isAuthenticated}
*
* @returns {boolean | null} isAuth: true if user is authenticated, false otherwise or null if the request has not finished.
*/
export const useAuth = (): [
boolean,
React.Dispatch<React.SetStateAction<boolean>>,
] => {
let isMounted = true;
const [isAuth, setIsAuth] = useState<boolean>(false);
useEffect(() => {
isAuthenticated().then((state) => {
if (isMounted) {
setIsAuth(state);
}
});
return () => {
isMounted = false;
};
}, []);
return [isAuth, setIsAuth];
};
import { fetchCookie } from 'api/fetchCookie';
import { useCallback, useEffect, useState } from 'react';
/**
* Custom hook that return csrf cookie fetched from server.
*
* @return cookie
*/
export const useCookie = (): string => {
const [cookie, setCookie] = useState('');
const askCookie = useCallback(() => {
let isMounted = true;
if (isMounted)
fetchCookie().then((cookieResponse) => setCookie(cookieResponse));
return () => {
isMounted = false;
};
}, []);
useEffect(() => {
askCookie();
}, [askCookie]);
return cookie;
};
import { getRole } from 'api/getRole';
import { useEffect, useState } from 'react';
export const useRole = (): [
string,
React.Dispatch<React.SetStateAction<string>>,
] => {
const [role, setRole] = useState('');
useEffect(() => {
let isMounted = true;
// Initialize asking the server if this session is already logged in.
getRole().then((responseRole) => {
if (isMounted) {
setRole(responseRole);
}
});
return () => {
isMounted = false;
};
}, []);
return [role, setRole];
};
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