@@ -14,6 +14,7 @@ export function AuthorizationCheck() {
1414 const router = useRouter ( ) ;
1515 const pathname = usePathname ( ) ;
1616 const [ isChecking , setIsChecking ] = useState ( true ) ;
17+ const [ shouldRedirect , setShouldRedirect ] = useState ( false ) ;
1718
1819 useEffect ( ( ) => {
1920 // Skip check if on access-denied page
@@ -24,25 +25,39 @@ export function AuthorizationCheck() {
2425
2526 // Wait for session to load
2627 if ( status === "loading" ) {
28+ setIsChecking ( true ) ;
29+ return ;
30+ }
31+
32+ // If unauthenticated, no need to check authorization
33+ if ( status === "unauthenticated" ) {
34+ setIsChecking ( false ) ;
35+ setShouldRedirect ( false ) ;
2736 return ;
2837 }
2938
3039 // Check authorization when session is loaded
3140 if ( status === "authenticated" && session ) {
3241 if ( session . unauthorized ) {
33- // Redirect immediately without showing content
42+ // Mark for redirect and keep checking state true
43+ setShouldRedirect ( true ) ;
44+ setIsChecking ( true ) ;
3445 router . push ( "/access-denied" ) ;
3546 return ;
3647 }
3748 }
3849
3950 // Authorization check complete
4051 setIsChecking ( false ) ;
52+ setShouldRedirect ( false ) ;
4153 } , [ session , status , pathname , router ] ) ;
4254
43- // Show loading overlay while checking authorization
55+ // Show loading overlay while checking authorization or redirecting
4456 // This prevents flash of unauthorized content
45- if ( isChecking && pathname !== "/access-denied" && pathname !== "/" ) {
57+ if (
58+ ( isChecking && pathname !== "/access-denied" ) ||
59+ ( shouldRedirect && pathname !== "/access-denied" )
60+ ) {
4661 return (
4762 < div
4863 style = { {
0 commit comments