import React from 'react'; import ReactDOM from 'react-dom/client'; import { BrowserRouter } from 'react-router-dom'; import { AuthProvider } from 'react-oidc-context'; import { Toaster } from 'react-hot-toast'; import App from './App'; import { oidcConfig } from './src/config/oidc'; // Clean up stale OAuth params on page load (e.g., after logout redirect) // This prevents "No matching state found in storage" errors const cleanupStaleOAuthParams = () => { const params = new URLSearchParams(window.location.search); const hasOAuthParams = params.has('code') || params.has('state'); if (hasOAuthParams) { const state = params.get('state'); // Check if there's a matching state in storage const hasMatchingState = state && localStorage.getItem(`oidc.${state}`); if (!hasMatchingState) { // Stale params - clean them up window.history.replaceState({}, document.title, window.location.pathname); } } }; cleanupStaleOAuthParams(); const rootElement = document.getElementById('root'); if (!rootElement) { throw new Error("Could not find root element to mount to"); } const shouldSkipSigninCallback = !window.location.pathname.startsWith('/callback'); const onSigninCallback = () => { window.history.replaceState({}, document.title, '/'); }; const root = ReactDOM.createRoot(rootElement); root.render( { localStorage.removeItem('kaboot_session'); }} > );