Skip to content

Commit 82eed3c

Browse files
authored
Merge pull request #422 from sahilds1/416-bugfix-stuck-spinner
BUGFIX: Fix stuck spinner
2 parents 8ca3f0f + 4297e40 commit 82eed3c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

frontend/src/components/ProtectedRoute/ProtectedRoute.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { ReactNode } from 'react';
1+
import { ReactNode, useEffect } from 'react';
22
import { Navigate, useLocation } from 'react-router-dom';
3-
import { useSelector } from 'react-redux';
3+
import { useSelector, useDispatch } from 'react-redux';
44
import { RootState } from '../../services/actions/types';
5+
import { AppDispatch, checkAuthenticated } from '../../services/actions/auth';
56
import Spinner from '../LoadingSpinner/LoadingSpinner';
67

78
interface ProtectedRouteProps {
@@ -10,8 +11,16 @@ interface ProtectedRouteProps {
1011

1112
const ProtectedRoute = ({ children }: ProtectedRouteProps) => {
1213
const location = useLocation();
14+
const dispatch = useDispatch<AppDispatch>();
1315
const { isAuthenticated } = useSelector((state: RootState) => state.auth);
14-
16+
17+
// Check authentication status when component mounts
18+
useEffect(() => {
19+
if (isAuthenticated === null) {
20+
dispatch(checkAuthenticated());
21+
}
22+
}, [dispatch, isAuthenticated]);
23+
1524
// Wait for auth check to complete (null means not checked yet)
1625
// TODO: Consider adding error handling for auth check failures
1726
if (isAuthenticated === null) {

0 commit comments

Comments
 (0)