Skip to content
Snippets Groups Projects

Polished auth flow including ReservedRoute and role selection.

Merged Defendi Alberto requested to merge feature/privateroute/role into dev
1 file
+ 6
19
Compare changes
  • Side-by-side
  • Inline
@@ -4,11 +4,10 @@ import { AuthRoutes } from 'api/routes';
import { isAuthenticated } from 'api/isAuthenticated';
import { CircularProgress } from '@material-ui/core';
/**
*
* */
type Props = {
/** Children where the authenticated user will be redirected. */
Component: React.FC<RouteProps>;
/** Path of the children. */
path: string;
};
@@ -25,23 +24,11 @@ export const RestrictedRoute = ({ Component, path }: Props): JSX.Element => {
const [isLoading, setLoading] = useState<boolean>(false);
useEffect(() => {
let isMounted = true;
isAuthenticated().then((state) => {
if (isMounted) {
setIsAuth(state);
setLoading(true);
}
});
return () => {
isMounted = false;
};
}, [isLoading]);
isAuthenticated().then((res) => setIsAuth(res));
console.log(isAuth);
}, [isAuth]);
return !isLoading ? (
<CircularProgress />
) : (
return (
<Route
path={path}
render={(props: RouteProps) =>
Loading