@realtek/core-theme 0.0.8 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,58 @@
1
1
  # CORE-THEME
2
2
  CORE-THEME 1
3
3
 
4
+ ## Auth handling for pages (built in)
5
+
6
+ When a page from this library (e.g. `AdminPage`, `JobsListPage`, …) is opened
7
+ **without a logged-in session**, the data APIs reject with a 401 and the page
8
+ would otherwise render empty ("no module") with no explanation.
9
+
10
+ This is handled **inside the package** — every exported page is already wrapped
11
+ with an auth guard. A host app does **nothing**: just route to the page, and if
12
+ it's opened without a session the user sees a clear *"You haven't logged into
13
+ this session. Please login to access the data."* screen with a **Login** button.
14
+
15
+ ```jsx
16
+ import { BrowserRouter, Routes, Route } from 'react-router-dom';
17
+ import { AdminPage } from '@realtek/core-theme';
18
+ import '@realtek/core-theme/style.css';
19
+
20
+ export default function App() {
21
+ return (
22
+ <BrowserRouter>
23
+ <Routes>
24
+ {/* opened without login → shows the "not logged in" screen automatically */}
25
+ <Route path="/admin" element={<AdminPage />} />
26
+ </Routes>
27
+ </BrowserRouter>
28
+ );
29
+ }
30
+ ```
31
+
32
+ ### Guarding your own pages (optional)
33
+
34
+ The same guard is exported for any custom page the host app builds:
35
+
36
+ ```jsx
37
+ import { AuthGuard, withAuthGuard } from '@realtek/core-theme';
38
+
39
+ // wrap inline…
40
+ <AuthGuard><MyPage /></AuthGuard>
41
+
42
+ // …or bake it into your own component, like the library does:
43
+ const MyGuardedPage = withAuthGuard(MyPage);
44
+ ```
45
+
46
+ ### Customizing the screen (`AuthGuard` / `withAuthGuard` props, all optional)
47
+
48
+ | Prop | Default | Purpose |
49
+ | ------------ | ------------------------------------------------------------------- | -------------------------------------------------- |
50
+ | `title` | `"You're not logged in"` | Heading on the error screen. |
51
+ | `message` | `"You haven't logged into this session. Please login to access the data."` | Sub-text. |
52
+ | `loginPath` | `"/login"` | Where the Login button sends the user. |
53
+ | `loginLabel` | `"Go to Login"` | Login button text. |
54
+ | `onLogin` | — | Custom handler for the Login button (overrides `loginPath`). |
55
+ | `fallback` | — | Render your own screen instead of the default one. |
56
+
57
+ The guard re-checks the session live on login, logout, tab focus and
58
+ cross-tab `storage` changes, so it reveals/hides content without a reload.