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

Replace context with api.

This keeps the user logged in after tab closing, since state is stored
in the server.
parent 6b871da1
No related branches found
No related tags found
2 merge requests!60New component to search senior (see #12). Enhance responsiveness and solve #10 and #11,!57Replace context with api.
This commit is part of merge request !60. Comments created here will be created in the context of that merge request.
......@@ -4,6 +4,8 @@ import { NonAuthRoutes } from 'api/routes';
import { Redirect } from 'react-router-dom';
import { Unauthorized } from 'components/Unauthorized/Unauthorized';
import { AuthContext } from 'components/Auth/AuthContext';
import { useRole } from 'hooks/useRole';
import { useAuth } from 'hooks/useAuth';
const HandleIsAuth: FC<{ isAuth: boolean }> = ({ isAuth }) =>
isAuth ? (
......@@ -35,11 +37,12 @@ export const withAuthorization = (allowedRoles: string[]) => <
const ComponentWithAuthorization: FC<T> = (
props: Omit<T, keyof WithAuthProps>,
) => {
const { role, isAuth } = useContext(AuthContext);
console.log(`ROLE ${role} AUTH ${isAuth}`);
const [role, setRole, isLoading] = useRole();
const [isAuth] = useAuth();
console.log(`ROLE ${role} AUTH ${isAuth} LOADED ${isLoading}`);
/* eslint-disable no-nested-ternary */
return typeof isAuth === null && role === null ? (
return isAuth === null || isLoading ? (
<BlurCircular />
) : // props comes afterwards so the can override the default ones.
allowedRoles.includes(role) && isAuth ? (
......
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