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.
...@@ -4,6 +4,8 @@ import { NonAuthRoutes } from 'api/routes'; ...@@ -4,6 +4,8 @@ import { NonAuthRoutes } from 'api/routes';
import { Redirect } from 'react-router-dom'; import { Redirect } from 'react-router-dom';
import { Unauthorized } from 'components/Unauthorized/Unauthorized'; import { Unauthorized } from 'components/Unauthorized/Unauthorized';
import { AuthContext } from 'components/Auth/AuthContext'; import { AuthContext } from 'components/Auth/AuthContext';
import { useRole } from 'hooks/useRole';
import { useAuth } from 'hooks/useAuth';
const HandleIsAuth: FC<{ isAuth: boolean }> = ({ isAuth }) => const HandleIsAuth: FC<{ isAuth: boolean }> = ({ isAuth }) =>
isAuth ? ( isAuth ? (
...@@ -35,11 +37,12 @@ export const withAuthorization = (allowedRoles: string[]) => < ...@@ -35,11 +37,12 @@ export const withAuthorization = (allowedRoles: string[]) => <
const ComponentWithAuthorization: FC<T> = ( const ComponentWithAuthorization: FC<T> = (
props: Omit<T, keyof WithAuthProps>, props: Omit<T, keyof WithAuthProps>,
) => { ) => {
const { role, isAuth } = useContext(AuthContext); const [role, setRole, isLoading] = useRole();
console.log(`ROLE ${role} AUTH ${isAuth}`); const [isAuth] = useAuth();
console.log(`ROLE ${role} AUTH ${isAuth} LOADED ${isLoading}`);
/* eslint-disable no-nested-ternary */ /* eslint-disable no-nested-ternary */
return typeof isAuth === null && role === null ? ( return isAuth === null || isLoading ? (
<BlurCircular /> <BlurCircular />
) : // props comes afterwards so the can override the default ones. ) : // props comes afterwards so the can override the default ones.
allowedRoles.includes(role) && isAuth ? ( 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