Skip to content

Commit

Permalink
fix: add loading state to handle authentication status check
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele-mng committed Oct 8, 2024
1 parent 48a2292 commit 5fabb0a
Showing 1 changed file with 13 additions and 1 deletion.
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 LocationObserver from 'web/components/observer/locationobserver';
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 LoggedInRoutes = () => {
};

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

0 comments on commit 5fabb0a

Please sign in to comment.