{"version":3,"file":"RequireAuth.mjs","sources":["../../../../src/lib/auth/authGuards/RequireAuth.tsx"],"sourcesContent":["import { memo, type ReactNode } from 'react';\nimport { Navigate, useLocation } from 'react-router-dom';\nimport { useAuth } from '../useAuth';\nimport { routes } from '@/lib/routing/routes';\nimport { AuthGuardLoading } from './AuthGuardLoading';\n\ninterface RequireAuthProps {\n  children: ReactNode;\n  /** Redirect path for unauthenticated users */\n  redirectTo?: string;\n  /** Custom loading state while checking auth */\n  fallback?: ReactNode;\n}\n\n/**\n * Guard component that requires authentication.\n * Redirects to login if not authenticated.\n *\n * @example\n * ```tsx\n * <RequireAuth>\n *   <ProtectedPage />\n * </RequireAuth>\n *\n * // With custom redirect\n * <RequireAuth redirectTo=\"/signin\">\n *   <ProtectedPage />\n * </RequireAuth>\n *\n * // With custom loading\n * <RequireAuth fallback={<CustomLoader />}>\n *   <ProtectedPage />\n * </RequireAuth>\n * ```\n */\nexport const RequireAuth = memo(\n  ({ children, redirectTo = routes.login, fallback }: RequireAuthProps) => {\n    const { isAuthenticated, isLoading } = useAuth();\n    const location = useLocation();\n\n    if (isLoading) {\n      return <AuthGuardLoading fallback={fallback} ariaLabel=\"Verifying authentication...\" />;\n    }\n\n    if (!isAuthenticated) {\n      // Redirect to login, preserving the intended destination\n      return <Navigate to={redirectTo} state={{ from: location }} replace />;\n    }\n\n    return <>{children}</>;\n  }\n);\n"],"names":["RequireAuth","memo","children","redirectTo","routes","fallback","isAuthenticated","isLoading","useAuth","location","useLocation","jsx","AuthGuardLoading","Navigate"],"mappings":";;;;;;AAmCO,MAAMA,IAAcC;AAAA,EACzB,CAAC,EAAE,UAAAC,GAAU,YAAAC,IAAaC,EAAO,OAAO,UAAAC,QAAiC;AACvE,UAAM,EAAE,iBAAAC,GAAiB,WAAAC,EAAA,IAAcC,EAAA,GACjCC,IAAWC,EAAA;AAEjB,WAAIH,IACK,gBAAAI,EAACC,GAAA,EAAiB,UAAAP,GAAoB,WAAU,8BAAA,CAA8B,IAGlFC,2BAKK,UAAAJ,GAAS,IAHV,gBAAAS,EAACE,GAAA,EAAS,IAAIV,GAAY,OAAO,EAAE,MAAMM,EAAA,GAAY,SAAO,GAAA,CAAC;AAAA,EAIxE;AACF;"}