Skip to content

Commit 1e39362

Browse files
committed
Merge branch '309-393-test-combined-prs' of https://github.com/CodeForPhilly/balancer-main into 309-393-test-combined-prs
2 parents 655dcf3 + 2b2e24c commit 1e39362

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

frontend/src/components/ProtectedRoute/ProtectedRoute.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ReactNode } from 'react';
22
import { Navigate, useLocation } from 'react-router-dom';
33
import { useSelector } from 'react-redux';
44
import { RootState } from '../../services/actions/types';
5+
import Spinner from '../LoadingSpinner/LoadingSpinner';
56

67
interface ProtectedRouteProps {
78
children: ReactNode;
@@ -10,13 +11,21 @@ interface ProtectedRouteProps {
1011
const ProtectedRoute = ({ children }: ProtectedRouteProps) => {
1112
const location = useLocation();
1213
const { isAuthenticated } = useSelector((state: RootState) => state.auth);
14+
15+
// Wait for auth check to complete (null means not checked yet)
16+
// TODO: Consider adding error handling for auth check failures
17+
if (isAuthenticated === null) {
18+
// TODO: Consider adding accessibility attributes (role="status", aria-live="polite", aria-label)
19+
// TODO: Consider preventing Loading State Flash by adding delay before showing spinner
20+
return <Spinner />;
21+
}
1322

1423
// If not authenticated, redirect to login and include the original location
1524
if (!isAuthenticated) {
1625
return <Navigate to="/login" replace state={{ from: location }} />;
1726
}
1827

19-
return <>{children}</>;
28+
return children;
2029
};
2130

2231
export default ProtectedRoute;

frontend/src/services/actions/types.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export const LOGOUT = "LOGOUT";
2121
export interface RootState {
2222
auth: {
2323
error: any;
24-
isAuthenticated: boolean;
24+
// Catch any code that doesn't handle the null case by matching the actual reducer state defined in auth.ts
25+
isAuthenticated: boolean | null;
2526
isSuperuser: boolean;
2627
};
2728
}

0 commit comments

Comments
 (0)