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:
parent
9532447271
commit
b394578a18
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue