11import type { RouteConfig } from "./types" ;
22import { RequireAdmin , RequireAuth , useAuth } from "../features/auth" ;
33import { useEffect } from "react" ;
4- import { Routes , Route , Navigate , useParams } from "react-router-dom" ;
4+ import { Routes , Route , Navigate , useParams , useLocation , matchPath } from "react-router-dom" ;
55import Loader from "../shared/ui/Loader" ;
66import { useTranslation } from "react-i18next" ;
77
@@ -54,6 +54,7 @@ const publicRoutes: RouteConfig[] = [
5454
5555export function AppRoutes ( ) {
5656 const { t } = useTranslation ( [ "login" ] ) ;
57+ const location = useLocation ( ) ;
5758 const {
5859 hydrated,
5960 isInitializing,
@@ -63,14 +64,26 @@ export function AppRoutes() {
6364 ensureAuth,
6465 } = useAuth ( ) ;
6566
67+ const isPublicRoute = publicRoutes . some ( ( route ) =>
68+ Boolean (
69+ matchPath (
70+ { path : route . path , end : true } ,
71+ location . pathname ,
72+ ) ,
73+ ) ,
74+ ) ;
75+
6676 useEffect ( ( ) => {
77+ if ( isPublicRoute ) return ;
6778 ensureAuth ( ) ;
68- } , [ ensureAuth ] ) ;
79+ } , [ ensureAuth , isPublicRoute ] ) ;
6980
7081 const isAuthBootstrapPending =
71- ! hydrated ||
72- isInitializing ||
73- ( ! isAuthenticated && refreshEnabled && ! hasChecked ) ;
82+ ! isPublicRoute && (
83+ ! hydrated ||
84+ isInitializing ||
85+ ( ! isAuthenticated && refreshEnabled && ! hasChecked )
86+ ) ;
7487
7588 if ( isAuthBootstrapPending ) {
7689 return (
0 commit comments