-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
41 lines (36 loc) · 1.51 KB
/
App.tsx
File metadata and controls
41 lines (36 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Route, Routes } from 'react-router-dom';
import { ApiError, useRegistry } from '@dar/data';
import { Layout } from './Layout';
import { HomePage } from './pages/HomePage';
import { ListPage } from './pages/ListPage';
import { DetailPage } from './pages/DetailPage';
import { LoginPage } from './pages/LoginPage';
export function App() {
const registry = useRegistry();
// Auth gate (Issue #167). When the registry load comes back
// unauthenticated (401) or forbidden (403), the session is invalid —
// render the React login full-screen instead of the admin layout.
// This only ever renders when the backend served the SPA shell to an
// anonymous user, i.e. the consumer set
// ``DJANGO_ADMIN_REACT["REACT_LOGIN"]``; otherwise ``SpaIndexView``
// redirected to the HTML login and the SPA never booted. Gating on
// the error status (not on ``data``) means a stale localStorage-cached
// registry can't keep a dead session looking alive.
const { error, refresh } = registry;
if (error instanceof ApiError && (error.status === 401 || error.status === 403)) {
return <LoginPage onSuccess={refresh} />;
}
return (
<Layout>
<Routes>
<Route path="/" element={<HomePage />} />
<Route path=":appLabel/:modelName" element={<ListPage />} />
<Route path=":appLabel/:modelName/:pk" element={<DetailPage />} />
<Route
path="*"
element={<div className="p-6 text-sm text-gray-500">Page not found.</div>}
/>
</Routes>
</Layout>
);
}