import { BrowserRouter, Routes, Route, Navigate, useLocation } from 'react-router-dom'; import { Toaster } from 'react-hot-toast'; import { useAuth, SignIn, SignUp } from '@clerk/clerk-react'; import React, { Suspense, lazy } from 'react'; import Layout from './components/dashboard/Layout'; import { ApiInterceptor } from './components/ApiInterceptor'; import { ErrorBoundary } from './components/common/ErrorBoundary'; import { CookieConsentBanner } from './components/common/CookieConsentBanner'; import { resolvePostAuthRedirect, safeSignInRedirectPath } from './utils/authGate'; const Pricing = lazy(() => import('./pages/Pricing')); const Projects = lazy(() => import('./pages/Projects')); const ProjectWorkspace = lazy(() => import('./pages/ProjectWorkspace')); const LandingPage = lazy(() => import('./pages/LandingPage')); const About = lazy(() => import('./pages/About')); const Help = lazy(() => import('./pages/Help')); const Settings = lazy(() => import('./pages/Settings')); const Regulamin = lazy(() => import('./pages/Regulamin')); const PolitykaPrywatnosci = lazy(() => import('./pages/PolitykaPrywatnosci')); const Nabory = lazy(() => import('./pages/Nabory')); const Pulse = lazy(() => import('./pages/Pulse')); const AdminDashboard = lazy(() => import('./pages/AdminDashboard')); const BetaGuide = lazy(() => import('./pages/BetaGuide')); const CompanyProfile = lazy(() => import('./pages/CompanyProfile')); const ReverseAudit = lazy(() => import('./pages/ReverseAudit')); const AuthBootSplash = () => (
Sprawdzanie sesji...
); /** Protected shell: wait for Clerk load; never bounce while session is hydrating. */ const ProtectedLayout = () => { const { isLoaded, isSignedIn } = useAuth(); const location = useLocation(); if (!isLoaded) { return ; } if (!isSignedIn) { const target = safeSignInRedirectPath(location.pathname, location.search); return ; } return ; }; /** Sign-in / sign-up: if already signed in, go to redirect_url or /projects (no /dashboard hop). */ const AuthRoute: React.FC<{ mode: 'sign-in' | 'sign-up' }> = ({ mode }) => { const { isLoaded, isSignedIn } = useAuth(); const location = useLocation(); const afterAuth = resolvePostAuthRedirect(location.search); if (!isLoaded) { return ; } if (isSignedIn) { return ; } return (
{mode === 'sign-in' ? ( ) : ( )}
); }; function App() { return ( Ładowanie aplikacji... }> {/* Ścieżki publiczne */} } /> } /> } /> {/* Strony prawne — publiczne (bez logowania) */} } /> } /> {/* Cennik — publiczny (widoczny przed logowaniem) */} } /> } /> {/* Ścieżki chronione (wymagające zalogowania) */} }> {/* Alias — no intermediate bounce that fights redirect_url */} } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> {/* Zabezpieczenie przed błędem nawigacji */} } /> ); } export default App;