Skip to content

Commit

Permalink
Merge pull request #4182 from greenbone/fix-add-loading-state-to-hand…
Browse files Browse the repository at this point in the history
…le-authentication-status-check

fix: add loading state to handle authentication status check
  • Loading branch information
daniele-mng authored Oct 9, 2024
2 parents 48a2292 + 5fabb0a commit a0de56d
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';

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';

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);
const isLoggedIn = useSelector(selectIsLoggedIn);

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

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

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

0 comments on commit a0de56d

Please sign in to comment.