File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
components/ProtectedRoute Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { ReactNode } from 'react';
22import { Navigate , useLocation } from 'react-router-dom' ;
33import { useSelector } from 'react-redux' ;
44import { RootState } from '../../services/actions/types' ;
5+ import Spinner from '../LoadingSpinner/LoadingSpinner' ;
56
67interface ProtectedRouteProps {
78 children : ReactNode ;
@@ -10,13 +11,21 @@ interface ProtectedRouteProps {
1011const 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
2231export default ProtectedRoute ;
Original file line number Diff line number Diff line change @@ -21,7 +21,8 @@ export const LOGOUT = "LOGOUT";
2121export 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}
You can’t perform that action at this time.
0 commit comments