diff --git a/app/src/frontend/route.tsx b/app/src/frontend/route.tsx index 62c38042..1d595d22 100644 --- a/app/src/frontend/route.tsx +++ b/app/src/frontend/route.tsx @@ -1,10 +1,11 @@ -import React from 'react' +import React, { Fragment } from 'react' import { Route, RouteProps, Redirect } from 'react-router-dom'; +import { SpinnerIcon } from './components/icons'; import { useAuth } from './auth-context'; export const PrivateRoute: React.FC = ({component: Component, children, ...rest}) => { - const { isAuthenticated } = useAuth(); + const { isAuthenticated, isLoading } = useAuth(); return = ({component: Component, childr } else if(children) { return <>{children}; } - + } else { + if (isLoading) { + return Loading user info... + } return ; } - }} + }} /> }; @@ -35,7 +39,7 @@ export const AuthRoute: React.FC = ({ component: Component, children if(isAuthenticated) { let state = props.location.state as any; let from = '/my-account.html'; - if ('from' in state){ + if (typeof state == 'object' && 'from' in state){ from = state.from; } @@ -47,6 +51,6 @@ export const AuthRoute: React.FC = ({ component: Component, children return <>{children}; } } - }} + }} /> }; diff --git a/app/src/frontend/user/login.tsx b/app/src/frontend/user/login.tsx index 2d189967..5a702610 100644 --- a/app/src/frontend/user/login.tsx +++ b/app/src/frontend/user/login.tsx @@ -20,7 +20,7 @@ export const Login: React.FC = () => { e.preventDefault(); setError(undefined); - login({ username, password }); + login({ username, password }, setError); }, [username, password]); return (