Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add loading state to handle authentication status check #4182

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/web/routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import React from 'react';
import {useState, useEffect} from 'react';

Check warning on line 6 in src/web/routes.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/routes.jsx#L6

Added line #L6 was not covered by tests

import {
BrowserRouter as Router,
Expand All @@ -16,6 +16,7 @@
import SessionObserver from 'web/components/observer/sessionobserver';

import ConditionalRoute from 'web/components/conditionalRoute/ConditionalRoute';
import Loading from 'web/components/loading/loading';

Check warning on line 19 in src/web/routes.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/routes.jsx#L19

Added line #L19 was not covered by tests

import LegacyOmpPage from './pages/omp';
import Page from './pages/page';
Expand Down Expand Up @@ -255,8 +256,19 @@
};

const AppRoutes = () => {
const [isLoading, setIsLoading] = useState(true);

Check warning on line 259 in src/web/routes.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/routes.jsx#L259

Added line #L259 was not covered by tests
const isLoggedIn = useSelector(selectIsLoggedIn);

useEffect(() => {
if (isLoggedIn !== undefined) {
setIsLoading(false);
}
}, [isLoggedIn]);

Check warning on line 266 in src/web/routes.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/routes.jsx#L262-L266

Added lines #L262 - L266 were not covered by tests

if (isLoading) {
return <Loading />;
}

Check warning on line 270 in src/web/routes.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/routes.jsx#L268-L270

Added lines #L268 - L270 were not covered by tests

return (
<Router>{isLoggedIn ? <LoggedInRoutes /> : <LoggedOutRoutes />}</Router>
);
Expand Down