@realtek/core-theme-live 0.0.338

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 ADDED
@@ -0,0 +1,80 @@
1
+ # CORE-THEME
2
+ CORE-THEME 1
3
+
4
+ ## Local setup and commit checks
5
+
6
+ After cloning the repo, run:
7
+
8
+ ```bash
9
+ npm run setup
10
+ ```
11
+
12
+ This installs dependencies with `npm ci` and configures Git to use the shared
13
+ `.githooks/pre-commit` hook. The hook runs impacted component tests before each
14
+ commit.
15
+
16
+ If dependencies are already installed, run:
17
+
18
+ ```bash
19
+ npm run install:hooks
20
+ ```
21
+
22
+ `npm run dev`, `npm test`, and `npm run build` also refresh the hook setup
23
+ automatically. Git hooks are local machine settings, so CI and branch protection
24
+ remain the final enforcement.
25
+
26
+ ## Auth handling for pages (built in)
27
+
28
+ When a page from this library (e.g. `AdminPage`, `JobsListPage`, …) is opened
29
+ **without a logged-in session**, the data APIs reject with a 401 and the page
30
+ would otherwise render empty ("no module") with no explanation.
31
+
32
+ This is handled **inside the package** — every exported page is already wrapped
33
+ with an auth guard. A host app does **nothing**: just route to the page, and if
34
+ it's opened without a session the user sees a clear *"You haven't logged into
35
+ this session. Please login to access the data."* screen with a **Login** button.
36
+
37
+ ```jsx
38
+ import { BrowserRouter, Routes, Route } from 'react-router-dom';
39
+ import { AdminPage } from '@realtek/core-theme';
40
+ import '@realtek/core-theme/style.css';
41
+
42
+ export default function App() {
43
+ return (
44
+ <BrowserRouter>
45
+ <Routes>
46
+ {/* opened without login → shows the "not logged in" screen automatically */}
47
+ <Route path="/admin" element={<AdminPage />} />
48
+ </Routes>
49
+ </BrowserRouter>
50
+ );
51
+ }
52
+ ```
53
+
54
+ ### Guarding your own pages (optional)
55
+
56
+ The same guard is exported for any custom page the host app builds:
57
+
58
+ ```jsx
59
+ import { AuthGuard, withAuthGuard } from '@realtek/core-theme';
60
+
61
+ // wrap inline…
62
+ <AuthGuard><MyPage /></AuthGuard>
63
+
64
+ // …or bake it into your own component, like the library does:
65
+ const MyGuardedPage = withAuthGuard(MyPage);
66
+ ```
67
+
68
+ ### Customizing the screen (`AuthGuard` / `withAuthGuard` props, all optional)
69
+
70
+ | Prop | Default | Purpose |
71
+ | ------------ | ------------------------------------------------------------------- | -------------------------------------------------- |
72
+ | `title` | `"You're not logged in"` | Heading on the error screen. |
73
+ | `message` | `"You haven't logged into this session. Please login to access the data."` | Sub-text. |
74
+ | `loginPath` | `"/login"` | Where the Login button sends the user. |
75
+ | `loginLabel` | `"Go to Login"` | Login button text. |
76
+ | `onLogin` | — | Custom handler for the Login button (overrides `loginPath`). |
77
+ | `fallback` | — | Render your own screen instead of the default one. |
78
+
79
+ The guard re-checks the session live on login, logout, tab focus and
80
+ cross-tab `storage` changes, so it reveals/hides content without a reload.