import { createRoot } from 'react-dom/client';
import './index.css';
import App from './App.tsx';
import { LogtoProvider } from '@logto/react';
import type { LogtoConfig } from '@logto/react';

// Require the user to define VITE_LOGTO_APP_ID in Coolify
const config: LogtoConfig = {
  endpoint: 'https://logto.reifonas.cloud',
  appId: import.meta.env.VITE_LOGTO_APP_ID || '', // Replace or add via Envs!
};

// Force service worker cache clearing because of persistent Clerk error
if ('serviceWorker' in navigator) {
  navigator.serviceWorker.getRegistrations().then(function(registrations) {
    for(let registration of registrations) {
      registration.unregister();
    }
  });
}

createRoot(document.getElementById('root')!).render(
  <LogtoProvider config={config}>
    <App />
  </LogtoProvider>
);
