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

Redirect to dashboard if user is auth.

parent fe15a7fb
No related branches found
No related tags found
2 merge requests!56Refined auth flow and new website pages.,!45Polished auth flow including ReservedRoute and role selection.
...@@ -4,11 +4,10 @@ import { AuthRoutes } from 'api/routes'; ...@@ -4,11 +4,10 @@ import { AuthRoutes } from 'api/routes';
import { isAuthenticated } from 'api/isAuthenticated'; import { isAuthenticated } from 'api/isAuthenticated';
import { CircularProgress } from '@material-ui/core'; import { CircularProgress } from '@material-ui/core';
/**
*
* */
type Props = { type Props = {
/** Children where the authenticated user will be redirected. */
Component: React.FC<RouteProps>; Component: React.FC<RouteProps>;
/** Path of the children. */
path: string; path: string;
}; };
...@@ -25,23 +24,11 @@ export const RestrictedRoute = ({ Component, path }: Props): JSX.Element => { ...@@ -25,23 +24,11 @@ export const RestrictedRoute = ({ Component, path }: Props): JSX.Element => {
const [isLoading, setLoading] = useState<boolean>(false); const [isLoading, setLoading] = useState<boolean>(false);
useEffect(() => { useEffect(() => {
let isMounted = true; isAuthenticated().then((res) => setIsAuth(res));
console.log(isAuth);
isAuthenticated().then((state) => { }, [isAuth]);
if (isMounted) {
setIsAuth(state);
setLoading(true);
}
});
return () => {
isMounted = false;
};
}, [isLoading]);
return !isLoading ? ( return (
<CircularProgress />
) : (
<Route <Route
path={path} path={path}
render={(props: RouteProps) => render={(props: RouteProps) =>
......
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