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.
This commit is contained in:
Jannis Mattheis 2025-09-13 10:34:07 +02:00
parent 9532447271
commit b394578a18
1 changed files with 14 additions and 6 deletions

View File

@ -55,6 +55,7 @@ const Layout = observer(() => {
const { const {
currentUser: { currentUser: {
loggedIn, loggedIn,
authenticating,
user: {name, admin}, user: {name, admin},
logout, logout,
tryReconnect, tryReconnect,
@ -79,7 +80,9 @@ const Layout = observer(() => {
}; };
const authed = (children: React.ReactNode) => ( const authed = (children: React.ReactNode) => (
<RequireAuth loggedIn={loggedIn}>{children}</RequireAuth> <RequireAuth loggedIn={loggedIn} authenticating={authenticating}>
{children}
</RequireAuth>
); );
return ( return (
@ -167,11 +170,16 @@ const Lazy = ({component}: {component: () => Promise<{default: React.ComponentTy
); );
}; };
const RequireAuth: React.FC<React.PropsWithChildren<{loggedIn: boolean}>> = ({ const RequireAuth: React.FC<
children, React.PropsWithChildren<{loggedIn: boolean; authenticating: boolean}>
loggedIn, > = ({children, authenticating, loggedIn}) => {
}) => { if (authenticating) {
return loggedIn ? <>{children}</> : <Navigate replace={true} to="/login" />; return <LoadingSpinner />;
}
if (!loggedIn) {
return <Navigate replace={true} to="/login" />;
}
return <>{children}</>;
}; };
export default Layout; export default Layout;