@object-ui/auth 3.0.0 → 3.0.2
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 +93 -1
- package/dist/AuthContext.d.ts +5 -1
- package/dist/AuthContext.d.ts.map +1 -1
- package/dist/AuthProvider.d.ts +14 -2
- package/dist/AuthProvider.d.ts.map +1 -1
- package/dist/AuthProvider.js +37 -6
- package/dist/PreviewBanner.d.ts +23 -0
- package/dist/PreviewBanner.d.ts.map +1 -0
- package/dist/PreviewBanner.js +27 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/types.d.ts +19 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/useAuth.d.ts.map +1 -1
- package/dist/useAuth.js +2 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@ Authentication system for Object UI — AuthProvider, guards, login/register for
|
|
|
10
10
|
- 👤 **UserMenu** - Display authenticated user info with sign-out support
|
|
11
11
|
- 🔑 **Auth Client Factory** - `createAuthClient` for pluggable backend integration
|
|
12
12
|
- 🌐 **Authenticated Fetch** - `createAuthenticatedFetch` for automatic token injection
|
|
13
|
+
- 👀 **Preview Mode** - Auto-login with simulated identity for marketplace demos and app showcases
|
|
13
14
|
- 🎯 **Type-Safe** - Full TypeScript support with exported types
|
|
14
15
|
|
|
15
16
|
## Installation
|
|
@@ -71,9 +72,31 @@ Wraps your application with authentication context:
|
|
|
71
72
|
Hook for accessing auth state and methods:
|
|
72
73
|
|
|
73
74
|
```tsx
|
|
74
|
-
const {
|
|
75
|
+
const {
|
|
76
|
+
user,
|
|
77
|
+
session,
|
|
78
|
+
signIn,
|
|
79
|
+
signOut,
|
|
80
|
+
signUp,
|
|
81
|
+
isAuthenticated,
|
|
82
|
+
isLoading,
|
|
83
|
+
isPreviewMode,
|
|
84
|
+
previewMode,
|
|
85
|
+
} = useAuth();
|
|
75
86
|
```
|
|
76
87
|
|
|
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
|
+
|
|
77
100
|
### AuthGuard
|
|
78
101
|
|
|
79
102
|
Protects children from unauthenticated access:
|
|
@@ -110,6 +133,75 @@ Creates a fetch wrapper that injects auth tokens into DataSource requests:
|
|
|
110
133
|
const authedFetch = createAuthenticatedFetch({ getToken: () => session.token });
|
|
111
134
|
```
|
|
112
135
|
|
|
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
|
+
|
|
113
205
|
## License
|
|
114
206
|
|
|
115
207
|
MIT
|
package/dist/AuthContext.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
-
import type { AuthUser, AuthSession } from './types';
|
|
8
|
+
import type { AuthUser, AuthSession, PreviewModeOptions } from './types';
|
|
9
9
|
export interface AuthContextValue {
|
|
10
10
|
/** Current authenticated user */
|
|
11
11
|
user: AuthUser | null;
|
|
@@ -17,6 +17,10 @@ export interface AuthContextValue {
|
|
|
17
17
|
isLoading: boolean;
|
|
18
18
|
/** Authentication error */
|
|
19
19
|
error: Error | null;
|
|
20
|
+
/** Whether the app is running in preview mode */
|
|
21
|
+
isPreviewMode: boolean;
|
|
22
|
+
/** Preview mode configuration (only set when isPreviewMode is true) */
|
|
23
|
+
previewMode: PreviewModeOptions | null;
|
|
20
24
|
/** Sign in with email and password */
|
|
21
25
|
signIn: (email: string, password: string) => Promise<void>;
|
|
22
26
|
/** Sign up with name, email, and password */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthContext.d.ts","sourceRoot":"","sources":["../src/AuthContext.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"AuthContext.d.ts","sourceRoot":"","sources":["../src/AuthContext.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAEzE,MAAM,WAAW,gBAAgB;IAC/B,iCAAiC;IACjC,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;IACtB,kCAAkC;IAClC,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5B,wCAAwC;IACxC,eAAe,EAAE,OAAO,CAAC;IACzB,oCAAoC;IACpC,SAAS,EAAE,OAAO,CAAC;IACnB,2BAA2B;IAC3B,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,iDAAiD;IACjD,aAAa,EAAE,OAAO,CAAC;IACvB,uEAAuE;IACvE,WAAW,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACvC,sCAAsC;IACtC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3D,6CAA6C;IAC7C,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzE,gCAAgC;IAChC,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,0BAA0B;IAC1B,UAAU,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,6BAA6B;IAC7B,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,gCAAgC;IAChC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtE;AAED,eAAO,MAAM,OAAO,kDAA+C,CAAC"}
|
package/dist/AuthProvider.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
import React from 'react';
|
|
9
|
-
import type { AuthProviderConfig } from './types';
|
|
9
|
+
import type { AuthProviderConfig, PreviewModeOptions } from './types';
|
|
10
10
|
export interface AuthProviderProps extends AuthProviderConfig {
|
|
11
11
|
children: React.ReactNode;
|
|
12
12
|
/**
|
|
@@ -16,6 +16,12 @@ export interface AuthProviderProps extends AuthProviderConfig {
|
|
|
16
16
|
* @default true
|
|
17
17
|
*/
|
|
18
18
|
enabled?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Preview mode configuration.
|
|
21
|
+
* When provided, the auth provider auto-logs in a simulated user and bypasses
|
|
22
|
+
* login/registration screens. Useful for marketplace demos and app showcases.
|
|
23
|
+
*/
|
|
24
|
+
previewMode?: PreviewModeOptions;
|
|
19
25
|
}
|
|
20
26
|
/**
|
|
21
27
|
* Authentication context provider.
|
|
@@ -36,6 +42,12 @@ export interface AuthProviderProps extends AuthProviderConfig {
|
|
|
36
42
|
* <App />
|
|
37
43
|
* </AuthProvider>
|
|
38
44
|
* ```
|
|
45
|
+
* @example With preview mode (marketplace demo)
|
|
46
|
+
* ```tsx
|
|
47
|
+
* <AuthProvider authUrl="/api/auth" previewMode={{ simulatedRole: 'admin', bannerMessage: 'Demo mode' }}>
|
|
48
|
+
* <App />
|
|
49
|
+
* </AuthProvider>
|
|
50
|
+
* ```
|
|
39
51
|
*/
|
|
40
|
-
export declare function AuthProvider({ authUrl, client: externalClient, onAuthStateChange, enabled, children, }: AuthProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
52
|
+
export declare function AuthProvider({ authUrl, client: externalClient, onAuthStateChange, enabled, previewMode, children, }: AuthProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
41
53
|
//# sourceMappingURL=AuthProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthProvider.d.ts","sourceRoot":"","sources":["../src/AuthProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAoD,MAAM,OAAO,CAAC;AACzE,OAAO,KAAK,EAAwB,kBAAkB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"AuthProvider.d.ts","sourceRoot":"","sources":["../src/AuthProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAoD,MAAM,OAAO,CAAC;AACzE,OAAO,KAAK,EAAwB,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAI5F,MAAM,WAAW,iBAAkB,SAAQ,kBAAkB;IAC3D,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,YAAY,CAAC,EAC3B,OAAO,EACP,MAAM,EAAE,cAAc,EACtB,iBAAiB,EACjB,OAAc,EACd,WAAW,EACX,QAAQ,GACT,EAAE,iBAAiB,2CAgNnB"}
|
package/dist/AuthProvider.js
CHANGED
|
@@ -28,19 +28,48 @@ import { createAuthClient } from './createAuthClient';
|
|
|
28
28
|
* <App />
|
|
29
29
|
* </AuthProvider>
|
|
30
30
|
* ```
|
|
31
|
+
* @example With preview mode (marketplace demo)
|
|
32
|
+
* ```tsx
|
|
33
|
+
* <AuthProvider authUrl="/api/auth" previewMode={{ simulatedRole: 'admin', bannerMessage: 'Demo mode' }}>
|
|
34
|
+
* <App />
|
|
35
|
+
* </AuthProvider>
|
|
36
|
+
* ```
|
|
31
37
|
*/
|
|
32
|
-
export function AuthProvider({ authUrl, client: externalClient, onAuthStateChange, enabled = true, children, }) {
|
|
38
|
+
export function AuthProvider({ authUrl, client: externalClient, onAuthStateChange, enabled = true, previewMode, children, }) {
|
|
33
39
|
const client = useMemo(() => externalClient ?? createAuthClient({ baseURL: authUrl }), [externalClient, authUrl]);
|
|
34
40
|
const [user, setUser] = useState(null);
|
|
35
41
|
const [session, setSession] = useState(null);
|
|
36
42
|
const [isLoading, setIsLoading] = useState(true);
|
|
37
43
|
const [error, setError] = useState(null);
|
|
38
|
-
//
|
|
39
|
-
const
|
|
44
|
+
// Determine if we're in preview mode
|
|
45
|
+
const isPreviewMode = previewMode != null;
|
|
46
|
+
// If auth is disabled or in preview mode, automatically set as authenticated
|
|
47
|
+
const isAuthenticated = (enabled && !isPreviewMode)
|
|
40
48
|
? user !== null && session !== null
|
|
41
49
|
: true;
|
|
42
|
-
// Load session on mount (only if auth is enabled)
|
|
50
|
+
// Load session on mount (only if auth is enabled and not in preview mode)
|
|
43
51
|
useEffect(() => {
|
|
52
|
+
if (isPreviewMode) {
|
|
53
|
+
// Preview mode: simulate a user based on previewMode config
|
|
54
|
+
const role = previewMode.simulatedRole ?? 'admin';
|
|
55
|
+
const name = previewMode.simulatedUserName ?? 'Preview User';
|
|
56
|
+
const expiresInSeconds = previewMode.expiresInSeconds ?? 0;
|
|
57
|
+
setUser({
|
|
58
|
+
id: 'preview-user',
|
|
59
|
+
email: 'preview@preview.local',
|
|
60
|
+
name,
|
|
61
|
+
role,
|
|
62
|
+
roles: [role],
|
|
63
|
+
});
|
|
64
|
+
setSession({
|
|
65
|
+
token: 'preview-token',
|
|
66
|
+
expiresAt: expiresInSeconds > 0
|
|
67
|
+
? new Date(Date.now() + expiresInSeconds * 1000)
|
|
68
|
+
: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000),
|
|
69
|
+
});
|
|
70
|
+
setIsLoading(false);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
44
73
|
if (!enabled) {
|
|
45
74
|
// When auth is disabled, set a guest user and mark as loaded
|
|
46
75
|
setUser({
|
|
@@ -79,7 +108,7 @@ export function AuthProvider({ authUrl, client: externalClient, onAuthStateChang
|
|
|
79
108
|
}
|
|
80
109
|
loadSession();
|
|
81
110
|
return () => { cancelled = true; };
|
|
82
|
-
}, [client, enabled]);
|
|
111
|
+
}, [client, enabled, isPreviewMode, previewMode]);
|
|
83
112
|
// Notify on auth state changes
|
|
84
113
|
useEffect(() => {
|
|
85
114
|
onAuthStateChange?.({
|
|
@@ -179,12 +208,14 @@ export function AuthProvider({ authUrl, client: externalClient, onAuthStateChang
|
|
|
179
208
|
isAuthenticated,
|
|
180
209
|
isLoading,
|
|
181
210
|
error,
|
|
211
|
+
isPreviewMode,
|
|
212
|
+
previewMode: isPreviewMode ? previewMode : null,
|
|
182
213
|
signIn,
|
|
183
214
|
signUp,
|
|
184
215
|
signOut,
|
|
185
216
|
updateUser,
|
|
186
217
|
forgotPassword,
|
|
187
218
|
resetPassword,
|
|
188
|
-
}), [user, session, isAuthenticated, isLoading, error, signIn, signUp, signOut, updateUser, forgotPassword, resetPassword]);
|
|
219
|
+
}), [user, session, isAuthenticated, isLoading, error, isPreviewMode, previewMode, signIn, signUp, signOut, updateUser, forgotPassword, resetPassword]);
|
|
189
220
|
return _jsx(AuthCtx.Provider, { value: value, children: children });
|
|
190
221
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export interface PreviewBannerProps {
|
|
9
|
+
/** Custom class name for the banner */
|
|
10
|
+
className?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Banner component that displays a message when the app is in preview mode.
|
|
14
|
+
* Only renders when preview mode is active. Uses the bannerMessage from
|
|
15
|
+
* preview mode config, or a default message if none is provided.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* <PreviewBanner />
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function PreviewBanner({ className }: PreviewBannerProps): import("react/jsx-runtime").JSX.Element | null;
|
|
23
|
+
//# sourceMappingURL=PreviewBanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PreviewBanner.d.ts","sourceRoot":"","sources":["../src/PreviewBanner.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,MAAM,WAAW,kBAAkB;IACjC,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,EAAE,SAAS,EAAE,EAAE,kBAAkB,kDAyB9D"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useAuth } from './useAuth';
|
|
3
|
+
/**
|
|
4
|
+
* Banner component that displays a message when the app is in preview mode.
|
|
5
|
+
* Only renders when preview mode is active. Uses the bannerMessage from
|
|
6
|
+
* preview mode config, or a default message if none is provided.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <PreviewBanner />
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export function PreviewBanner({ className }) {
|
|
14
|
+
const { isPreviewMode, previewMode } = useAuth();
|
|
15
|
+
if (!isPreviewMode) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const message = previewMode?.bannerMessage ?? 'You are in preview mode.';
|
|
19
|
+
return (_jsx("div", { role: "status", className: className, style: {
|
|
20
|
+
padding: '8px 16px',
|
|
21
|
+
backgroundColor: '#fef3c7',
|
|
22
|
+
color: '#92400e',
|
|
23
|
+
textAlign: 'center',
|
|
24
|
+
fontSize: '14px',
|
|
25
|
+
borderBottom: '1px solid #fcd34d',
|
|
26
|
+
}, children: message }));
|
|
27
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -26,9 +26,10 @@ export { LoginForm, type LoginFormProps } from './LoginForm';
|
|
|
26
26
|
export { RegisterForm, type RegisterFormProps } from './RegisterForm';
|
|
27
27
|
export { ForgotPasswordForm, type ForgotPasswordFormProps } from './ForgotPasswordForm';
|
|
28
28
|
export { UserMenu, type UserMenuProps } from './UserMenu';
|
|
29
|
+
export { PreviewBanner, type PreviewBannerProps } from './PreviewBanner';
|
|
29
30
|
export { createAuthClient } from './createAuthClient';
|
|
30
31
|
export { createAuthenticatedFetch, type AuthenticatedAdapterOptions } from './createAuthenticatedFetch';
|
|
31
32
|
export { getUserInitials } from './types';
|
|
32
|
-
export type { AuthUser, AuthSession, AuthState, AuthClient, AuthClientConfig, AuthProviderConfig, SignInCredentials, SignUpData, } from './types';
|
|
33
|
+
export type { AuthUser, AuthSession, AuthState, AuthClient, AuthClientConfig, AuthProviderConfig, PreviewModeOptions, SignInCredentials, SignUpData, } from './types';
|
|
33
34
|
export type { AuthContextValue } from './AuthContext';
|
|
34
35
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,KAAK,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,wBAAwB,EAAE,KAAK,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AACxG,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG1C,YA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|
@@ -26,6 +26,7 @@ export { LoginForm } from './LoginForm';
|
|
|
26
26
|
export { RegisterForm } from './RegisterForm';
|
|
27
27
|
export { ForgotPasswordForm } from './ForgotPasswordForm';
|
|
28
28
|
export { UserMenu } from './UserMenu';
|
|
29
|
+
export { PreviewBanner } from './PreviewBanner';
|
|
29
30
|
export { createAuthClient } from './createAuthClient';
|
|
30
31
|
export { createAuthenticatedFetch } from './createAuthenticatedFetch';
|
|
31
32
|
export { getUserInitials } from './types';
|
package/dist/types.d.ts
CHANGED
|
@@ -98,6 +98,25 @@ export interface AuthClient {
|
|
|
98
98
|
/** Update user profile */
|
|
99
99
|
updateUser: (data: Partial<AuthUser>) => Promise<AuthUser>;
|
|
100
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Preview mode configuration options.
|
|
103
|
+
* When preview mode is active, the auth provider auto-logs in a simulated user
|
|
104
|
+
* and bypasses login/registration screens.
|
|
105
|
+
*/
|
|
106
|
+
export interface PreviewModeOptions {
|
|
107
|
+
/** Auto-login as simulated user, skipping login/registration pages */
|
|
108
|
+
autoLogin?: boolean;
|
|
109
|
+
/** Permission role for the simulated preview user */
|
|
110
|
+
simulatedRole?: 'admin' | 'user' | 'viewer';
|
|
111
|
+
/** Display name for the simulated preview user */
|
|
112
|
+
simulatedUserName?: string;
|
|
113
|
+
/** Restrict the preview session to read-only operations */
|
|
114
|
+
readOnly?: boolean;
|
|
115
|
+
/** Preview session duration in seconds (0 = no expiration) */
|
|
116
|
+
expiresInSeconds?: number;
|
|
117
|
+
/** Banner message displayed in the UI during preview mode */
|
|
118
|
+
bannerMessage?: string;
|
|
119
|
+
}
|
|
101
120
|
/** Auth provider configuration */
|
|
102
121
|
export interface AuthProviderConfig {
|
|
103
122
|
/** Authentication server URL */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAE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K,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrE,0BAA0B;IAC1B,UAAU,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC5D;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,sEAAsE;IACtE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,qDAAqD;IACrD,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;IAC5C,kDAAkD;IAClD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,8DAA8D;IAC9D,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,6DAA6D;IAC7D,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,kCAAkC;AAClC,MAAM,WAAW,kBAAkB;IACjC,gCAAgC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,uCAAuC;IACvC,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IAC/C,iDAAiD;IACjD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
|
package/dist/useAuth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../src/useAuth.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAW,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE/D;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,IAAI,gBAAgB,
|
|
1
|
+
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../src/useAuth.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAW,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE/D;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,IAAI,gBAAgB,CAuB1C"}
|
package/dist/useAuth.js
CHANGED
|
@@ -30,6 +30,8 @@ export function useAuth() {
|
|
|
30
30
|
isAuthenticated: false,
|
|
31
31
|
isLoading: false,
|
|
32
32
|
error: null,
|
|
33
|
+
isPreviewMode: false,
|
|
34
|
+
previewMode: null,
|
|
33
35
|
signIn: async () => { throw new Error('useAuth must be used within an AuthProvider'); },
|
|
34
36
|
signUp: async () => { throw new Error('useAuth must be used within an AuthProvider'); },
|
|
35
37
|
signOut: async () => { throw new Error('useAuth must be used within an AuthProvider'); },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/auth",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Authentication system for Object UI with AuthProvider, useAuth hook, AuthGuard, and form components.",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"react": "^18.0.0 || ^19.0.0"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@object-ui/types": "3.0.
|
|
29
|
+
"@object-ui/types": "3.0.2"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/react": "19.2.13",
|