Skip to content

Commit a4df074

Browse files
Copilothotlong
andcommitted
docs: add preview mode documentation to auth README, react README, and changelogs
- packages/auth/README.md: Add Preview Mode section with usage, PreviewModeOptions table, PreviewBanner docs, and detection example - packages/auth/README.md: Update useAuth hook docs with isPreviewMode and previewMode fields - packages/auth/CHANGELOG.md: Add preview mode feature entries - packages/react/README.md: Add useDiscovery hook docs with DiscoveryInfo and preview mode fields - CHANGELOG.md: Add @objectstack v3.0.4 upgrade and preview mode feature entries Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent f5a8b12 commit a4df074

4 files changed

Lines changed: 149 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Changed
1111

12+
- **@objectstack v3.0.4 Upgrade**: Upgraded all `@objectstack/*` packages from `^3.0.2` to `^3.0.4` across 42 references
1213
- **@objectstack v3.0.0 Upgrade**: Upgraded all `@objectstack/*` packages from `^2.0.7` to `^3.0.0` across 13 package.json files
1314
- **Breaking change migrations**:
1415
- `Hub` namespace → `Cloud` in @object-ui/types re-exports
@@ -22,6 +23,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2223

2324
### Added
2425

26+
- **Preview Mode** (`@object-ui/auth`): New `previewMode` prop on `AuthProvider` for auto-login with simulated identity — skip login/registration for marketplace demos and app showcases. Includes `PreviewBanner` component, `isPreviewMode` / `previewMode` on `useAuth()`, and `PreviewModeOptions` type. Aligns with `@objectstack/spec` kernel `PreviewModeConfig`.
27+
- **Discovery Preview Detection** (`@object-ui/react`): Extended `DiscoveryInfo` with `mode` and `previewMode` fields for server-driven preview mode detection.
28+
- **Console Preview Support**: `ConditionalAuthWrapper` auto-detects `mode === 'preview'` from server discovery and configures auth accordingly.
2529
- **Console Bundle Optimization**: Split monolithic 3.7 MB main chunk into 17 granular cacheable chunks via `manualChunks` — main entry reduced from 1,008 KB gzip to 48.5 KB gzip (95% reduction)
2630
- **Gzip + Brotli Compression**: Pre-compressed assets via `vite-plugin-compression2` — Brotli main entry at 40 KB
2731
- **Bundle Analysis**: Added `rollup-plugin-visualizer` generating interactive treemap at `dist/stats.html`; new `build:analyze` script

packages/auth/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66

77
- @object-ui/types@3.0.1
88

9+
### Added
10+
11+
- **Preview Mode** (`previewMode` prop on `AuthProvider`): Auto-login with simulated identity for marketplace demos and app showcases. Configurable role, display name, session expiry, read-only mode, and banner message.
12+
- **PreviewBanner** component: Renders a status banner when preview mode is active.
13+
- `isPreviewMode` and `previewMode` fields exposed on `AuthContextValue` / `useAuth()` hook.
14+
- New `PreviewModeOptions` type mirroring spec's `PreviewModeConfig`.
15+
16+
### Changed
17+
18+
- Upgraded `@objectstack/spec` from `^3.0.2` to `^3.0.4`.
19+
920
## 3.0.0
1021

1122
### Minor Changes

packages/auth/README.md

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Authentication system for Object UI — AuthProvider, guards, login/register for
1010
- 👤 **UserMenu** - Display authenticated user info with sign-out support
1111
- 🔑 **Auth Client Factory** - `createAuthClient` for pluggable backend integration
1212
- 🌐 **Authenticated Fetch** - `createAuthenticatedFetch` for automatic token injection
13+
- 👀 **Preview Mode** - Auto-login with simulated identity for marketplace demos and app showcases
1314
- 🎯 **Type-Safe** - Full TypeScript support with exported types
1415

1516
## Installation
@@ -71,9 +72,31 @@ Wraps your application with authentication context:
7172
Hook for accessing auth state and methods:
7273

7374
```tsx
74-
const { user, session, signIn, signOut, signUp, isAuthenticated, isLoading } = useAuth();
75+
const {
76+
user,
77+
session,
78+
signIn,
79+
signOut,
80+
signUp,
81+
isAuthenticated,
82+
isLoading,
83+
isPreviewMode,
84+
previewMode,
85+
} = useAuth();
7586
```
7687

88+
| Property | Type | Description |
89+
| --- | --- | --- |
90+
| `user` | `AuthUser \| null` | Current authenticated user |
91+
| `session` | `AuthSession \| null` | Current session information |
92+
| `isAuthenticated` | `boolean` | Whether the user is authenticated |
93+
| `isLoading` | `boolean` | Whether auth state is loading |
94+
| `isPreviewMode` | `boolean` | Whether the app is running in preview mode |
95+
| `previewMode` | `PreviewModeOptions \| null` | Preview mode configuration (only set when `isPreviewMode` is true) |
96+
| `signIn` | `(email, password) => Promise` | Sign in with credentials |
97+
| `signOut` | `() => Promise` | Sign out the current user |
98+
| `signUp` | `(name, email, password) => Promise` | Register a new user |
99+
77100
### AuthGuard
78101

79102
Protects children from unauthenticated access:
@@ -110,6 +133,75 @@ Creates a fetch wrapper that injects auth tokens into DataSource requests:
110133
const authedFetch = createAuthenticatedFetch({ getToken: () => session.token });
111134
```
112135

136+
## Preview Mode
137+
138+
Preview mode allows visitors (e.g. marketplace customers) to explore the platform without registering or logging in. The `AuthProvider` auto-authenticates with a simulated user identity and bypasses login/registration screens.
139+
140+
This feature aligns with the `PreviewModeConfig` from `@objectstack/spec/kernel` ([spec PR #676](https://github.com/objectstack-ai/spec/pull/676)).
141+
142+
### Usage
143+
144+
```tsx
145+
import { AuthProvider, PreviewBanner } from '@object-ui/auth';
146+
147+
function App() {
148+
return (
149+
<AuthProvider
150+
authUrl="/api/auth"
151+
previewMode={{
152+
simulatedRole: 'admin',
153+
simulatedUserName: 'Demo Admin',
154+
readOnly: false,
155+
bannerMessage: 'You are exploring a demo — data will be reset periodically.',
156+
}}
157+
>
158+
<PreviewBanner />
159+
<Dashboard />
160+
</AuthProvider>
161+
);
162+
}
163+
```
164+
165+
### PreviewModeOptions
166+
167+
| Property | Type | Default | Description |
168+
| --- | --- | --- | --- |
169+
| `autoLogin` | `boolean` | `true` | Auto-login as simulated user, skipping login/registration pages |
170+
| `simulatedRole` | `'admin' \| 'user' \| 'viewer'` | `'admin'` | Permission role for the simulated preview user |
171+
| `simulatedUserName` | `string` | `'Preview User'` | Display name for the simulated preview user |
172+
| `readOnly` | `boolean` | `false` | Restrict the preview session to read-only operations |
173+
| `expiresInSeconds` | `number` | `0` | Preview session duration in seconds (0 = no expiration) |
174+
| `bannerMessage` | `string` || Banner message displayed in the UI during preview mode |
175+
176+
### PreviewBanner
177+
178+
A component that renders a status banner when preview mode is active. Shows `bannerMessage` from the preview config, or a default message.
179+
180+
```tsx
181+
import { PreviewBanner } from '@object-ui/auth';
182+
183+
// Only renders when isPreviewMode is true
184+
<PreviewBanner />
185+
```
186+
187+
### Detecting Preview Mode
188+
189+
Use the `useAuth` hook to check if the app is in preview mode:
190+
191+
```tsx
192+
function MyComponent() {
193+
const { isPreviewMode, previewMode } = useAuth();
194+
195+
if (isPreviewMode && previewMode?.readOnly) {
196+
// Disable write operations
197+
}
198+
199+
return <div>...</div>;
200+
}
201+
```
202+
203+
> **⚠️ Security:** Preview mode should **never** be used in production environments.
204+
113205
## License
114206

115207
MIT

packages/react/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,47 @@ function MyComponent() {
112112
}
113113
```
114114

115+
### useDiscovery
116+
117+
Access server discovery information including preview mode detection:
118+
119+
```tsx
120+
import { useDiscovery } from '@object-ui/react'
121+
122+
function MyComponent() {
123+
const { discovery, isLoading, isAuthEnabled } = useDiscovery()
124+
125+
// Check if the server is in preview mode
126+
if (discovery?.mode === 'preview') {
127+
console.log('Preview mode active:', discovery.previewMode)
128+
}
129+
130+
return <div>Server: {discovery?.name}</div>
131+
}
132+
```
133+
134+
#### DiscoveryInfo
135+
136+
| Property | Type | Description |
137+
| --- | --- | --- |
138+
| `name` | `string` | Server name |
139+
| `version` | `string` | Server version |
140+
| `mode` | `string` | Runtime mode (e.g. `'development'`, `'production'`, `'preview'`) |
141+
| `previewMode` | `object` | Preview mode configuration (present when mode is `'preview'`) |
142+
| `services` | `object` | Service availability status (auth, data, metadata) |
143+
| `capabilities` | `string[]` | API capabilities |
144+
145+
The `previewMode` object contains:
146+
147+
| Property | Type | Default | Description |
148+
| --- | --- | --- | --- |
149+
| `autoLogin` | `boolean` | `true` | Skip login/registration pages |
150+
| `simulatedRole` | `'admin' \| 'user' \| 'viewer'` | `'admin'` | Simulated user role |
151+
| `simulatedUserName` | `string` | `'Preview User'` | Display name |
152+
| `readOnly` | `boolean` | `false` | Read-only mode |
153+
| `expiresInSeconds` | `number` | `0` | Session duration (0 = no expiry) |
154+
| `bannerMessage` | `string` || UI banner message |
155+
115156
## API Reference
116157

117158
See [full documentation](https://objectui.org/api/react) for detailed API reference.

0 commit comments

Comments
 (0)