Skip to content

Commit b394578

Browse files
committed
fix: preserve url path when refreshing the page
Don't redirect to /#/login when the tryAuthenticate hasn't completed. This caused the url path to be changed to /#/login regardaless if the user was already logged in.
1 parent 9532447 commit b394578

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

‎ui/src/layout/Layout.tsx‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const Layout = observer(() => {
5555
const {
5656
currentUser: {
5757
loggedIn,
58+
authenticating,
5859
user: {name, admin},
5960
logout,
6061
tryReconnect,
@@ -79,7 +80,9 @@ const Layout = observer(() => {
7980
};
8081

8182
const authed = (children: React.ReactNode) => (
82-
<RequireAuth loggedIn={loggedIn}>{children}</RequireAuth>
83+
<RequireAuth loggedIn={loggedIn} authenticating={authenticating}>
84+
{children}
85+
</RequireAuth>
8386
);
8487

8588
return (
@@ -167,11 +170,16 @@ const Lazy = ({component}: {component: () => Promise<{default: React.ComponentTy
167170
);
168171
};
169172

170-
const RequireAuth: React.FC<React.PropsWithChildren<{loggedIn: boolean}>> = ({
171-
children,
172-
loggedIn,
173-
}) => {
174-
return loggedIn ? <>{children}</> : <Navigate replace={true} to="/login" />;
173+
const RequireAuth: React.FC<
174+
React.PropsWithChildren<{loggedIn: boolean; authenticating: boolean}>
175+
> = ({children, authenticating, loggedIn}) => {
176+
if (authenticating) {
177+
return <LoadingSpinner />;
178+
}
179+
if (!loggedIn) {
180+
return <Navigate replace={true} to="/login" />;
181+
}
182+
return <>{children}</>;
175183
};
176184

177185
export default Layout;

0 commit comments

Comments
 (0)