feat: add src/main.tsx
This commit is contained in:
parent
b24219194f
commit
bf185e9858
33
src/main.tsx
Normal file
33
src/main.tsx
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import ReactDOM from 'react-dom/client'
|
||||||
|
import { registerSW } from 'virtual:pwa-register'
|
||||||
|
import { App } from './App'
|
||||||
|
import './styles.css'
|
||||||
|
|
||||||
|
async function bootstrap() {
|
||||||
|
registerSW({ immediate: true })
|
||||||
|
|
||||||
|
const session = await fetch('/api/session', { headers: { Accept: 'application/json' } })
|
||||||
|
if (session.status === 401) {
|
||||||
|
window.location.assign('/auth/login')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!session.ok) throw new Error(`Session check failed: ${session.status}`)
|
||||||
|
|
||||||
|
const payload = await session.json()
|
||||||
|
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||||
|
<React.StrictMode>
|
||||||
|
<App user={payload.user} />
|
||||||
|
</React.StrictMode>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
bootstrap().catch(error => {
|
||||||
|
document.body.innerHTML = `
|
||||||
|
<main style="font-family:system-ui;padding:24px;max-width:720px;margin:auto">
|
||||||
|
<h1>Template Studio</h1>
|
||||||
|
<p>Unable to start the application.</p>
|
||||||
|
<pre style="white-space:pre-wrap">${String(error)}</pre>
|
||||||
|
</main>
|
||||||
|
`
|
||||||
|
})
|
||||||
Loading…
x
Reference in New Issue
Block a user