From e478e182a5283b37439fcb1f4644e434d7295400 Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Fri, 22 Jul 2022 15:52:16 +0100 Subject: [PATCH 1/3] More robust check for location state Testing 'string' in var fails if var is not an object, throwing uncaught error and leaving a white screen on login. --- app/src/frontend/route.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/frontend/route.tsx b/app/src/frontend/route.tsx index 62c38042..c780fec2 100644 --- a/app/src/frontend/route.tsx +++ b/app/src/frontend/route.tsx @@ -35,7 +35,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; } From 187dc20baa9cd7a17c356ad83176b8906f055606 Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Fri, 22 Jul 2022 16:05:20 +0100 Subject: [PATCH 2/3] Handle isLoading state in private routes Additional check for isLoading to handle redirect after sign-up. --- app/src/frontend/route.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/frontend/route.tsx b/app/src/frontend/route.tsx index c780fec2..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 ; } - }} + }} /> }; @@ -47,6 +51,6 @@ export const AuthRoute: React.FC = ({ component: Component, children return <>{children}; } } - }} + }} /> }; From 5be87921fb997224368f83013c8b18139265281c Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Fri, 22 Jul 2022 16:11:40 +0100 Subject: [PATCH 3/3] Pass setError callback in login form Login failures (incorrect username or password) were silently failing, with no error message displayed. --- app/src/frontend/user/login.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 (