@lumoauth/react 0.0.0-stage → 1.1.0
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/LICENSE +21 -0
- package/README.md +642 -2
- package/dist/index.d.mts +686 -0
- package/dist/index.d.ts +686 -0
- package/dist/index.js +2499 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2451 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +67 -5
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,686 @@
|
|
|
1
|
+
import { EmailCheckResult, TokenStorage, AbacCheckRequest, LumoAuth, ZanzibarCheckRequest } from '@lumoauth/client';
|
|
2
|
+
export { LumoAuth, LumoAuthConfig } from '@lumoauth/client';
|
|
3
|
+
import * as React$1 from 'react';
|
|
4
|
+
import React__default from 'react';
|
|
5
|
+
|
|
6
|
+
interface LumoAuthUser {
|
|
7
|
+
/** Unique user ID */
|
|
8
|
+
id: string | number;
|
|
9
|
+
/** Primary email */
|
|
10
|
+
email: string;
|
|
11
|
+
/** First name */
|
|
12
|
+
firstName?: string;
|
|
13
|
+
/** Last name */
|
|
14
|
+
lastName?: string;
|
|
15
|
+
/** Display name (computed: firstName + lastName or email) */
|
|
16
|
+
displayName: string;
|
|
17
|
+
/** URL to user's avatar/profile image */
|
|
18
|
+
avatarUrl?: string;
|
|
19
|
+
/** Whether email has been verified */
|
|
20
|
+
emailVerified: boolean;
|
|
21
|
+
/** Whether MFA is enabled */
|
|
22
|
+
mfaEnabled: boolean;
|
|
23
|
+
/** List of role slugs */
|
|
24
|
+
roles: string[];
|
|
25
|
+
/** List of group names */
|
|
26
|
+
groups: string[];
|
|
27
|
+
/** OIDC subject identifier */
|
|
28
|
+
sub?: string;
|
|
29
|
+
/** Any additional custom claims from the ID token or UserInfo */
|
|
30
|
+
claims: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
type AuthStatus = 'loading' | 'authenticated' | 'unauthenticated';
|
|
33
|
+
interface AuthState {
|
|
34
|
+
/** Current auth status */
|
|
35
|
+
status: AuthStatus;
|
|
36
|
+
/** Authenticated user, or null */
|
|
37
|
+
user: LumoAuthUser | null;
|
|
38
|
+
/** Whether the initial auth check has completed */
|
|
39
|
+
isLoaded: boolean;
|
|
40
|
+
/** Shorthand: status === 'authenticated' */
|
|
41
|
+
isSignedIn: boolean;
|
|
42
|
+
}
|
|
43
|
+
interface LumoAuthProviderProps {
|
|
44
|
+
/** Your LumoAuth instance domain (e.g. "https://auth.example.com") */
|
|
45
|
+
domain: string;
|
|
46
|
+
/** Your organization ID (e.g. "acme-corp") */
|
|
47
|
+
orgId: string;
|
|
48
|
+
/** OAuth client ID */
|
|
49
|
+
clientId: string;
|
|
50
|
+
/**
|
|
51
|
+
* Authentication strategy.
|
|
52
|
+
* - `'pkce'` — OAuth 2.0 Authorization Code + PKCE (default, recommended)
|
|
53
|
+
* - `'password'` — Resource Owner Password Credentials grant (legacy)
|
|
54
|
+
*
|
|
55
|
+
* @default 'pkce'
|
|
56
|
+
*/
|
|
57
|
+
authStrategy?: 'pkce' | 'password';
|
|
58
|
+
/** OAuth redirect URI for the callback page (required for PKCE mode) */
|
|
59
|
+
redirectUri?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Space-separated OAuth scopes to request at sign-in and sign-up.
|
|
62
|
+
* Default: `"openid profile email"`. Add `abac:read` for `useAbac` and
|
|
63
|
+
* `<Protect abac>`, and `authz:read` for `listSlugs()` / `permissions.list()`.
|
|
64
|
+
* The application must also be allowed to request each scope.
|
|
65
|
+
*/
|
|
66
|
+
scope?: string;
|
|
67
|
+
/** URL to redirect after sign-in (defaults to current page) */
|
|
68
|
+
afterSignInUrl?: string;
|
|
69
|
+
/** URL to redirect after sign-up */
|
|
70
|
+
afterSignUpUrl?: string;
|
|
71
|
+
/** URL to redirect after sign-out (defaults to "/") */
|
|
72
|
+
afterSignOutUrl?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Where to keep tokens. Defaults to `sessionStorage` in the browser and
|
|
75
|
+
* memory on the server.
|
|
76
|
+
*
|
|
77
|
+
* Import an adapter from `@lumoauth/client`:
|
|
78
|
+
* `sessionStorageAdapter` (default, per-tab), `localStorageAdapter`
|
|
79
|
+
* (shared across tabs, survives restart), `memoryStorageAdapter`, or
|
|
80
|
+
* `cookieStorageAdapter` — the last keeps tokens in an httpOnly cookie so
|
|
81
|
+
* they are never readable by JavaScript, which is the only option that
|
|
82
|
+
* survives XSS. It requires a same-origin backend to own the exchange and
|
|
83
|
+
* refresh (see `@lumoauth/express`).
|
|
84
|
+
*/
|
|
85
|
+
storage?: TokenStorage;
|
|
86
|
+
/**
|
|
87
|
+
* Share the session across browser tabs: a refresh in one tab is broadcast
|
|
88
|
+
* to the others, and a Web Lock elects a single refresher so tabs do not
|
|
89
|
+
* race on a rotated refresh token.
|
|
90
|
+
* @default true
|
|
91
|
+
*/
|
|
92
|
+
crossTab?: boolean;
|
|
93
|
+
/** React children */
|
|
94
|
+
children: React.ReactNode;
|
|
95
|
+
}
|
|
96
|
+
interface AppearanceProps {
|
|
97
|
+
/** Force light or dark theme (defaults to system preference) */
|
|
98
|
+
theme?: 'light' | 'dark';
|
|
99
|
+
/** Override CSS custom properties */
|
|
100
|
+
variables?: Record<string, string>;
|
|
101
|
+
/** Additional className applied to the component root */
|
|
102
|
+
className?: string;
|
|
103
|
+
}
|
|
104
|
+
interface SignInProps {
|
|
105
|
+
/** URL to redirect after successful sign-in */
|
|
106
|
+
afterSignInUrl?: string;
|
|
107
|
+
/** URL for the sign-up link */
|
|
108
|
+
signUpUrl?: string;
|
|
109
|
+
/** Appearance overrides */
|
|
110
|
+
appearance?: AppearanceProps;
|
|
111
|
+
/**
|
|
112
|
+
* Social providers to offer, e.g. `['google', 'apple']`.
|
|
113
|
+
*
|
|
114
|
+
* Defaults to `[]` (no buttons). There is deliberately no default list:
|
|
115
|
+
* which providers an organization has enabled is only readable through
|
|
116
|
+
* `/orgs/{orgId}/api/v1/admin/social-providers`, which requires admin
|
|
117
|
+
* credentials and so is unreachable from an unauthenticated sign-in card.
|
|
118
|
+
* A hardcoded default would advertise providers the organization may not
|
|
119
|
+
* have configured.
|
|
120
|
+
*
|
|
121
|
+
* Each button deep-links straight to that provider: the SDK passes
|
|
122
|
+
* `?provider=` to `/oauth/authorize`, which redirects to the provider's
|
|
123
|
+
* flow with the PKCE challenge preserved. A provider the organization has
|
|
124
|
+
* not configured falls back to the hosted login page rather than erroring,
|
|
125
|
+
* so a wrong value degrades instead of breaking.
|
|
126
|
+
*
|
|
127
|
+
* Recognised icons: `google`, `github`, `microsoft`, `apple`. Any other
|
|
128
|
+
* value renders with a label and no icon.
|
|
129
|
+
*/
|
|
130
|
+
socialProviders?: string[];
|
|
131
|
+
}
|
|
132
|
+
interface SignUpProps {
|
|
133
|
+
/** URL to redirect after successful sign-up */
|
|
134
|
+
afterSignUpUrl?: string;
|
|
135
|
+
/** URL for the sign-in link */
|
|
136
|
+
signInUrl?: string;
|
|
137
|
+
/** Appearance overrides */
|
|
138
|
+
appearance?: AppearanceProps;
|
|
139
|
+
}
|
|
140
|
+
interface UserButtonProps {
|
|
141
|
+
/** URL to redirect after sign-out */
|
|
142
|
+
afterSignOutUrl?: string;
|
|
143
|
+
/** Show the user's name next to the avatar */
|
|
144
|
+
showName?: boolean;
|
|
145
|
+
/** Appearance overrides */
|
|
146
|
+
appearance?: AppearanceProps;
|
|
147
|
+
}
|
|
148
|
+
interface ProtectProps {
|
|
149
|
+
/** RBAC permission slug to check */
|
|
150
|
+
permission?: string;
|
|
151
|
+
/** Zanzibar ReBAC check */
|
|
152
|
+
zanzibar?: {
|
|
153
|
+
object: string;
|
|
154
|
+
relation: string;
|
|
155
|
+
subject?: string;
|
|
156
|
+
};
|
|
157
|
+
/** ABAC policy check */
|
|
158
|
+
abac?: {
|
|
159
|
+
resourceType: string;
|
|
160
|
+
action: string;
|
|
161
|
+
resourceId?: string;
|
|
162
|
+
};
|
|
163
|
+
/** Component to show when access is denied */
|
|
164
|
+
fallback?: React.ReactNode;
|
|
165
|
+
/** React children (shown when access is granted) */
|
|
166
|
+
children: React.ReactNode;
|
|
167
|
+
}
|
|
168
|
+
interface AuthCallbackProps {
|
|
169
|
+
/** URL to redirect after successful authentication (defaults to afterSignInUrl) */
|
|
170
|
+
afterSignInUrl?: string;
|
|
171
|
+
/** Custom loading component */
|
|
172
|
+
loading?: React.ReactNode;
|
|
173
|
+
/** Custom error component */
|
|
174
|
+
error?: React.ReactNode | ((error: string) => React.ReactNode);
|
|
175
|
+
}
|
|
176
|
+
interface SignedInProps {
|
|
177
|
+
/** React children (shown only when user is authenticated) */
|
|
178
|
+
children: React.ReactNode;
|
|
179
|
+
}
|
|
180
|
+
interface SignedOutProps {
|
|
181
|
+
/** React children (shown only when user is NOT authenticated) */
|
|
182
|
+
children: React.ReactNode;
|
|
183
|
+
}
|
|
184
|
+
interface SignInButtonProps {
|
|
185
|
+
/** Custom children to render inside the button */
|
|
186
|
+
children?: React.ReactNode;
|
|
187
|
+
/** Force redirect to a specific sign-in URL */
|
|
188
|
+
signInUrl?: string;
|
|
189
|
+
/** Additional class name */
|
|
190
|
+
className?: string;
|
|
191
|
+
}
|
|
192
|
+
interface SignUpButtonProps {
|
|
193
|
+
/** Custom children to render inside the button */
|
|
194
|
+
children?: React.ReactNode;
|
|
195
|
+
/** Force redirect to a specific sign-up URL */
|
|
196
|
+
signUpUrl?: string;
|
|
197
|
+
/** Additional class name */
|
|
198
|
+
className?: string;
|
|
199
|
+
}
|
|
200
|
+
interface SignOutButtonProps {
|
|
201
|
+
/** Custom children to render inside the button */
|
|
202
|
+
children?: React.ReactNode;
|
|
203
|
+
/** URL to redirect after sign-out */
|
|
204
|
+
afterSignOutUrl?: string;
|
|
205
|
+
/** Additional class name */
|
|
206
|
+
className?: string;
|
|
207
|
+
}
|
|
208
|
+
interface UserAvatarProps {
|
|
209
|
+
/** Avatar size in pixels */
|
|
210
|
+
size?: number;
|
|
211
|
+
/** Avatar shape */
|
|
212
|
+
shape?: 'circle' | 'square';
|
|
213
|
+
/** Appearance overrides */
|
|
214
|
+
appearance?: AppearanceProps;
|
|
215
|
+
}
|
|
216
|
+
interface UserProfileProps {
|
|
217
|
+
/** URL to redirect after sign-out */
|
|
218
|
+
afterSignOutUrl?: string;
|
|
219
|
+
/**
|
|
220
|
+
* Display mode:
|
|
221
|
+
* - `'full'` — shows all sections (account, security, roles)
|
|
222
|
+
* - `'compact'` — shows only account details
|
|
223
|
+
* @default 'full'
|
|
224
|
+
*/
|
|
225
|
+
mode?: 'full' | 'compact';
|
|
226
|
+
/** Appearance overrides */
|
|
227
|
+
appearance?: AppearanceProps;
|
|
228
|
+
}
|
|
229
|
+
interface RedirectToSignInProps {
|
|
230
|
+
/** Override sign-in URL */
|
|
231
|
+
signInUrl?: string;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Return type of the {@link useMagicLink} hook.
|
|
235
|
+
* Provides the `sendMagicLink` action plus loading/sent/error state.
|
|
236
|
+
*/
|
|
237
|
+
interface UseMagicLinkReturn {
|
|
238
|
+
/**
|
|
239
|
+
* Send a magic sign-in link to the given email.
|
|
240
|
+
* The server never reveals whether the email exists.
|
|
241
|
+
*/
|
|
242
|
+
sendMagicLink: (email: string, redirectUri?: string) => Promise<void>;
|
|
243
|
+
/** True while the request is in-flight */
|
|
244
|
+
isLoading: boolean;
|
|
245
|
+
/** True after the request completes (link was dispatched) */
|
|
246
|
+
isSent: boolean;
|
|
247
|
+
/** Error message if the request failed */
|
|
248
|
+
error: string | null;
|
|
249
|
+
/** Reset sent/error state back to idle */
|
|
250
|
+
reset: () => void;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Return type of the {@link useEmailFirst} hook.
|
|
254
|
+
* Provides the `checkEmail` action plus loading/result state.
|
|
255
|
+
*/
|
|
256
|
+
interface UseEmailFirstReturn {
|
|
257
|
+
/**
|
|
258
|
+
* Discover which sign-in methods this identifier can actually use.
|
|
259
|
+
*
|
|
260
|
+
* Returns the organization's enabled methods AND what this user has
|
|
261
|
+
* enrolled (passkey, push device, magic link, password), so a sign-in card
|
|
262
|
+
* can render only the options that will work.
|
|
263
|
+
*/
|
|
264
|
+
checkEmail: (email: string) => Promise<EmailCheckResult>;
|
|
265
|
+
/** True while the check is in-flight */
|
|
266
|
+
isLoading: boolean;
|
|
267
|
+
/** Full result of the last check, or null if not yet checked */
|
|
268
|
+
result: EmailCheckResult | null;
|
|
269
|
+
/** Shorthand for `result?.exists`, or null if not yet checked */
|
|
270
|
+
exists: boolean | null;
|
|
271
|
+
/** Reset state back to idle */
|
|
272
|
+
reset: () => void;
|
|
273
|
+
}
|
|
274
|
+
interface LumoAuthContextValue extends AuthState {
|
|
275
|
+
/**
|
|
276
|
+
* Sign in.
|
|
277
|
+
* - **PKCE mode:** Call with no args to initiate redirect-based sign-in.
|
|
278
|
+
* - **Password mode:** Call with `(email, password)` for inline sign-in.
|
|
279
|
+
*/
|
|
280
|
+
signIn: (email?: string, password?: string) => Promise<void> | void;
|
|
281
|
+
/** Sign in by redirecting to the LumoAuth authorization endpoint (PKCE). */
|
|
282
|
+
signInWithRedirect: () => void;
|
|
283
|
+
/** Sign in with a social provider using PKCE. */
|
|
284
|
+
signInWithSocial: (provider: string) => void;
|
|
285
|
+
/** Sign up with email, password, and optional name (password mode only). */
|
|
286
|
+
signUp: (params: {
|
|
287
|
+
email: string;
|
|
288
|
+
password: string;
|
|
289
|
+
firstName?: string;
|
|
290
|
+
lastName?: string;
|
|
291
|
+
}) => Promise<void>;
|
|
292
|
+
/**
|
|
293
|
+
* Sign out the current user. Revokes the access token, clears local
|
|
294
|
+
* tokens, and redirects the browser through the OIDC RP-initiated
|
|
295
|
+
* logout endpoint so the IdP session cookie is also invalidated.
|
|
296
|
+
*/
|
|
297
|
+
signOut: (options?: {
|
|
298
|
+
afterSignOutUrl?: string;
|
|
299
|
+
}) => Promise<void>;
|
|
300
|
+
/** Get the current access token (refreshes if expired) */
|
|
301
|
+
getToken: () => Promise<string | null>;
|
|
302
|
+
/** Handle the OAuth callback — exchange code for tokens */
|
|
303
|
+
handleCallback: () => Promise<void>;
|
|
304
|
+
/**
|
|
305
|
+
* Request a magic sign-in link for the given email.
|
|
306
|
+
* Shows a "Check your inbox" page — works for both email-first and
|
|
307
|
+
* magic-link-only organization configurations.
|
|
308
|
+
*/
|
|
309
|
+
sendMagicLink: (email: string, redirectUri?: string) => Promise<void>;
|
|
310
|
+
/**
|
|
311
|
+
* Check whether an account with the given email exists in the organization.
|
|
312
|
+
* Used to implement email-first login flows.
|
|
313
|
+
*/
|
|
314
|
+
checkEmail: (email: string) => Promise<EmailCheckResult>;
|
|
315
|
+
/** The authentication strategy in use */
|
|
316
|
+
authStrategy: 'pkce' | 'password';
|
|
317
|
+
/** Provider configuration */
|
|
318
|
+
config: {
|
|
319
|
+
domain: string;
|
|
320
|
+
orgId: string;
|
|
321
|
+
clientId: string;
|
|
322
|
+
redirectUri?: string;
|
|
323
|
+
afterSignInUrl?: string;
|
|
324
|
+
afterSignUpUrl?: string;
|
|
325
|
+
afterSignOutUrl?: string;
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
declare function LumoAuthProvider({ domain, orgId, clientId, authStrategy, redirectUri, scope, afterSignInUrl, afterSignUpUrl, afterSignOutUrl, storage, crossTab, children, }: LumoAuthProviderProps): React$1.JSX.Element;
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Drop-in sign-in component.
|
|
333
|
+
*
|
|
334
|
+
* - **PKCE mode (default):** Renders social login buttons and a
|
|
335
|
+
* "Sign in with email" button that redirects to the LumoAuth
|
|
336
|
+
* hosted login page. No inline password form.
|
|
337
|
+
*
|
|
338
|
+
* - **Password mode:** Renders the classic inline email/password form
|
|
339
|
+
* with social login buttons.
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```tsx
|
|
343
|
+
* import { SignIn } from '@lumoauth/react';
|
|
344
|
+
* <SignIn afterSignInUrl="/dashboard" />
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
declare function SignIn({ afterSignInUrl, signUpUrl, appearance, socialProviders, }: SignInProps): React__default.JSX.Element | null;
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Drop-in sign-up/registration component.
|
|
351
|
+
*
|
|
352
|
+
* - **PKCE mode (default):** Renders a button that redirects to the
|
|
353
|
+
* LumoAuth hosted registration page.
|
|
354
|
+
*
|
|
355
|
+
* - **Password mode:** Renders the inline registration form with
|
|
356
|
+
* password strength indicator.
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```tsx
|
|
360
|
+
* import { SignUp } from '@lumoauth/react';
|
|
361
|
+
* <SignUp afterSignUpUrl="/onboarding" />
|
|
362
|
+
* ```
|
|
363
|
+
*/
|
|
364
|
+
declare function SignUp({ afterSignUpUrl, signInUrl, appearance, }: SignUpProps): React__default.JSX.Element | null;
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Handles the OAuth callback after a PKCE redirect.
|
|
368
|
+
* Place this component on your callback route (e.g. `/auth/callback`).
|
|
369
|
+
*
|
|
370
|
+
* Automatically:
|
|
371
|
+
* 1. Parses the authorization code and state from the URL
|
|
372
|
+
* 2. Exchanges the code for tokens using the PKCE verifier
|
|
373
|
+
* 3. Redirects to `afterSignInUrl` on success
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* ```tsx
|
|
377
|
+
* // In your router, at the /auth/callback route:
|
|
378
|
+
* import { AuthCallback } from '@lumoauth/react';
|
|
379
|
+
*
|
|
380
|
+
* export function CallbackPage() {
|
|
381
|
+
* return <AuthCallback afterSignInUrl="/dashboard" />;
|
|
382
|
+
* }
|
|
383
|
+
* ```
|
|
384
|
+
*/
|
|
385
|
+
declare function AuthCallback({ afterSignInUrl, loading, error: errorComponent, }: AuthCallbackProps): React$1.JSX.Element;
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Clerk-style user avatar button with dropdown menu.
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```tsx
|
|
392
|
+
* import { UserButton } from '@lumoauth/react';
|
|
393
|
+
* <UserButton afterSignOutUrl="/" />
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
declare function UserButton({ afterSignOutUrl, showName, appearance, }: UserButtonProps): React__default.JSX.Element | null;
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Renders the current user's avatar. Displays the profile image
|
|
400
|
+
* if available, otherwise shows initials.
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```tsx
|
|
404
|
+
* import { UserAvatar } from '@lumoauth/react';
|
|
405
|
+
*
|
|
406
|
+
* // Default (32px)
|
|
407
|
+
* <UserAvatar />
|
|
408
|
+
*
|
|
409
|
+
* // Large with custom size
|
|
410
|
+
* <UserAvatar size={48} />
|
|
411
|
+
*
|
|
412
|
+
* // Square shape
|
|
413
|
+
* <UserAvatar shape="square" />
|
|
414
|
+
* ```
|
|
415
|
+
*/
|
|
416
|
+
declare function UserAvatar({ size, shape, appearance, }: UserAvatarProps): React__default.JSX.Element;
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Renders a user profile card showing account details, roles,
|
|
420
|
+
* security status, and a sign-out action.
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* ```tsx
|
|
424
|
+
* import { UserProfile } from '@lumoauth/react';
|
|
425
|
+
*
|
|
426
|
+
* // Full profile card
|
|
427
|
+
* <UserProfile />
|
|
428
|
+
*
|
|
429
|
+
* // With sign-out redirect
|
|
430
|
+
* <UserProfile afterSignOutUrl="/" />
|
|
431
|
+
*
|
|
432
|
+
* // Compact mode (hides roles and security sections)
|
|
433
|
+
* <UserProfile mode="compact" />
|
|
434
|
+
* ```
|
|
435
|
+
*/
|
|
436
|
+
declare function UserProfile({ afterSignOutUrl, mode, appearance, }: UserProfileProps): React__default.JSX.Element | null;
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Authorization gate component. Renders children only if the user
|
|
440
|
+
* has the required permission, relationship, or policy access.
|
|
441
|
+
*
|
|
442
|
+
* Supports RBAC, ReBAC (Zanzibar), and ABAC checks.
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* ```tsx
|
|
446
|
+
* // RBAC
|
|
447
|
+
* <Protect permission="documents.edit" fallback={<NoAccess />}>
|
|
448
|
+
* <EditForm />
|
|
449
|
+
* </Protect>
|
|
450
|
+
*
|
|
451
|
+
* // ReBAC (Zanzibar). Without `subject`, the check is about the
|
|
452
|
+
* // signed-in user (`user:<sub>`).
|
|
453
|
+
* <Protect zanzibar={{ object: 'doc:123', relation: 'editor' }}>
|
|
454
|
+
* <EditForm />
|
|
455
|
+
* </Protect>
|
|
456
|
+
*
|
|
457
|
+
* // ABAC
|
|
458
|
+
* <Protect abac={{ resourceType: 'document', action: 'read', resourceId: 'doc-123' }}>
|
|
459
|
+
* <ReadView />
|
|
460
|
+
* </Protect>
|
|
461
|
+
* ```
|
|
462
|
+
*/
|
|
463
|
+
declare function Protect({ permission, zanzibar, abac, fallback, children, }: ProtectProps): React__default.JSX.Element;
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Renders children only when the user is authenticated.
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* ```tsx
|
|
470
|
+
* <SignedIn>
|
|
471
|
+
* <p>Welcome back!</p>
|
|
472
|
+
* </SignedIn>
|
|
473
|
+
* ```
|
|
474
|
+
*/
|
|
475
|
+
declare function SignedIn({ children }: SignedInProps): React$1.JSX.Element | null;
|
|
476
|
+
/**
|
|
477
|
+
* Renders children only when the user is NOT authenticated.
|
|
478
|
+
*
|
|
479
|
+
* @example
|
|
480
|
+
* ```tsx
|
|
481
|
+
* <SignedOut>
|
|
482
|
+
* <p>Please sign in to continue.</p>
|
|
483
|
+
* </SignedOut>
|
|
484
|
+
* ```
|
|
485
|
+
*/
|
|
486
|
+
declare function SignedOut({ children }: SignedOutProps): React$1.JSX.Element | null;
|
|
487
|
+
/**
|
|
488
|
+
* Unstyled button that triggers sign-in.
|
|
489
|
+
* In PKCE mode, initiates the redirect flow.
|
|
490
|
+
* In password mode, navigates to the sign-in page.
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* ```tsx
|
|
494
|
+
* <SignInButton>
|
|
495
|
+
* <button className="my-custom-btn">Sign in</button>
|
|
496
|
+
* </SignInButton>
|
|
497
|
+
* ```
|
|
498
|
+
*/
|
|
499
|
+
declare function SignInButton({ children, signInUrl, className }: SignInButtonProps): React$1.JSX.Element;
|
|
500
|
+
/**
|
|
501
|
+
* Unstyled button that navigates to the sign-up page.
|
|
502
|
+
*
|
|
503
|
+
* @example
|
|
504
|
+
* ```tsx
|
|
505
|
+
* <SignUpButton>
|
|
506
|
+
* <button className="my-custom-btn">Sign up</button>
|
|
507
|
+
* </SignUpButton>
|
|
508
|
+
* ```
|
|
509
|
+
*/
|
|
510
|
+
declare function SignUpButton({ children, signUpUrl, className }: SignUpButtonProps): React$1.JSX.Element;
|
|
511
|
+
/**
|
|
512
|
+
* Unstyled button that triggers sign-out.
|
|
513
|
+
*
|
|
514
|
+
* @example
|
|
515
|
+
* ```tsx
|
|
516
|
+
* <SignOutButton afterSignOutUrl="/">
|
|
517
|
+
* <button>Log out</button>
|
|
518
|
+
* </SignOutButton>
|
|
519
|
+
* ```
|
|
520
|
+
*/
|
|
521
|
+
declare function SignOutButton({ children, afterSignOutUrl, className }: SignOutButtonProps): React$1.JSX.Element;
|
|
522
|
+
/**
|
|
523
|
+
* Automatically redirects to the sign-in page when rendered.
|
|
524
|
+
* Useful for protecting routes.
|
|
525
|
+
*
|
|
526
|
+
* @example
|
|
527
|
+
* ```tsx
|
|
528
|
+
* // In your protected route:
|
|
529
|
+
* <SignedOut>
|
|
530
|
+
* <RedirectToSignIn />
|
|
531
|
+
* </SignedOut>
|
|
532
|
+
* ```
|
|
533
|
+
*/
|
|
534
|
+
declare function RedirectToSignIn({ signInUrl }: RedirectToSignInProps): null;
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Primary hook for accessing auth state and actions.
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* ```tsx
|
|
541
|
+
* const { user, isSignedIn, signIn, signOut } = useAuth();
|
|
542
|
+
* ```
|
|
543
|
+
*/
|
|
544
|
+
declare function useAuth(): LumoAuthContextValue;
|
|
545
|
+
/**
|
|
546
|
+
* Returns the current user object, or null if not signed in.
|
|
547
|
+
*
|
|
548
|
+
* @example
|
|
549
|
+
* ```tsx
|
|
550
|
+
* const user = useUser();
|
|
551
|
+
* if (user) console.log(user.email);
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
554
|
+
declare function useUser(): LumoAuthUser | null;
|
|
555
|
+
/**
|
|
556
|
+
* Returns sign-in utilities.
|
|
557
|
+
*
|
|
558
|
+
* @example
|
|
559
|
+
* ```tsx
|
|
560
|
+
* const { signIn, signInWithRedirect, isLoading } = useSignIn();
|
|
561
|
+
* ```
|
|
562
|
+
*/
|
|
563
|
+
declare function useSignIn(): {
|
|
564
|
+
signIn: (email?: string, password?: string) => Promise<void> | void;
|
|
565
|
+
signInWithRedirect: () => void;
|
|
566
|
+
isLoading: boolean;
|
|
567
|
+
};
|
|
568
|
+
/**
|
|
569
|
+
* Returns session-related state.
|
|
570
|
+
*
|
|
571
|
+
* @example
|
|
572
|
+
* ```tsx
|
|
573
|
+
* const { isActive, isLoaded, getToken } = useSession();
|
|
574
|
+
* ```
|
|
575
|
+
*/
|
|
576
|
+
declare function useSession(): {
|
|
577
|
+
isActive: boolean;
|
|
578
|
+
isLoaded: boolean;
|
|
579
|
+
getToken: () => Promise<string | null>;
|
|
580
|
+
status: AuthStatus;
|
|
581
|
+
};
|
|
582
|
+
/**
|
|
583
|
+
* Returns a configured `LumoAuth` SDK client for making authorization
|
|
584
|
+
* checks (RBAC, ReBAC, ABAC). The client's token is automatically
|
|
585
|
+
* wired to the current session.
|
|
586
|
+
*
|
|
587
|
+
* @example
|
|
588
|
+
* ```tsx
|
|
589
|
+
* const client = useLumoAuth();
|
|
590
|
+
* const canEdit = await client.permissions.check('documents.edit');
|
|
591
|
+
* ```
|
|
592
|
+
*/
|
|
593
|
+
declare function useLumoAuth(): LumoAuth;
|
|
594
|
+
/**
|
|
595
|
+
* Check an RBAC permission. Returns loading and allowed states.
|
|
596
|
+
*
|
|
597
|
+
* @example
|
|
598
|
+
* ```tsx
|
|
599
|
+
* const { allowed, isLoading } = usePermission('documents.edit');
|
|
600
|
+
* if (isLoading) return <Spinner />;
|
|
601
|
+
* if (!allowed) return <NoAccess />;
|
|
602
|
+
* ```
|
|
603
|
+
*/
|
|
604
|
+
declare function usePermission(slug: string): {
|
|
605
|
+
allowed: boolean;
|
|
606
|
+
isLoading: boolean;
|
|
607
|
+
};
|
|
608
|
+
/**
|
|
609
|
+
* Check a Zanzibar ReBAC relationship. Returns loading and allowed states.
|
|
610
|
+
*
|
|
611
|
+
* @example
|
|
612
|
+
* ```tsx
|
|
613
|
+
* const { allowed, isLoading } = useZanzibar({
|
|
614
|
+
* object: 'document:readme',
|
|
615
|
+
* relation: 'editor',
|
|
616
|
+
* subject: 'user:alice',
|
|
617
|
+
* });
|
|
618
|
+
* ```
|
|
619
|
+
*/
|
|
620
|
+
declare function useZanzibar(request: ZanzibarCheckRequest): {
|
|
621
|
+
allowed: boolean;
|
|
622
|
+
isLoading: boolean;
|
|
623
|
+
};
|
|
624
|
+
/**
|
|
625
|
+
* Check an ABAC policy. Returns loading and allowed states.
|
|
626
|
+
*
|
|
627
|
+
* @example
|
|
628
|
+
* ```tsx
|
|
629
|
+
* const { allowed, isLoading } = useAbac({
|
|
630
|
+
* resourceType: 'document',
|
|
631
|
+
* action: 'read',
|
|
632
|
+
* resourceId: 'doc-123',
|
|
633
|
+
* });
|
|
634
|
+
* ```
|
|
635
|
+
*/
|
|
636
|
+
declare function useAbac(request: AbacCheckRequest): {
|
|
637
|
+
allowed: boolean;
|
|
638
|
+
isLoading: boolean;
|
|
639
|
+
};
|
|
640
|
+
/**
|
|
641
|
+
* Hook for requesting a magic sign-in link.
|
|
642
|
+
*
|
|
643
|
+
* Handles loading/sent/error state so you can build a fully-controlled
|
|
644
|
+
* "passwordless sign-in" form without any extra local state.
|
|
645
|
+
*
|
|
646
|
+
* @example
|
|
647
|
+
* ```tsx
|
|
648
|
+
* const { sendMagicLink, isLoading, isSent, error, reset } = useMagicLink();
|
|
649
|
+
*
|
|
650
|
+
* if (isSent) return <p>Check your inbox!</p>;
|
|
651
|
+
*
|
|
652
|
+
* return (
|
|
653
|
+
* <form onSubmit={e => { e.preventDefault(); sendMagicLink(email); }}>
|
|
654
|
+
* <input value={email} onChange={e => setEmail(e.target.value)} type="email" />
|
|
655
|
+
* <button type="submit" disabled={isLoading}>
|
|
656
|
+
* {isLoading ? 'Sending…' : 'Send sign-in link'}
|
|
657
|
+
* </button>
|
|
658
|
+
* {error && <p>{error}</p>}
|
|
659
|
+
* </form>
|
|
660
|
+
* );
|
|
661
|
+
* ```
|
|
662
|
+
*/
|
|
663
|
+
declare function useMagicLink(): UseMagicLinkReturn;
|
|
664
|
+
/**
|
|
665
|
+
* Hook for email-first login flows.
|
|
666
|
+
*
|
|
667
|
+
* Checks whether an account exists for the given email before showing
|
|
668
|
+
* the password or magic-link step.
|
|
669
|
+
*
|
|
670
|
+
* @example
|
|
671
|
+
* ```tsx
|
|
672
|
+
* const { checkEmail, isLoading, exists, reset } = useEmailFirst();
|
|
673
|
+
*
|
|
674
|
+
* async function handleEmailSubmit(email: string) {
|
|
675
|
+
* const found = await checkEmail(email);
|
|
676
|
+
* if (found) {
|
|
677
|
+
* // show password / magic-link step
|
|
678
|
+
* } else {
|
|
679
|
+
* // show "no account found" or sign-up prompt
|
|
680
|
+
* }
|
|
681
|
+
* }
|
|
682
|
+
* ```
|
|
683
|
+
*/
|
|
684
|
+
declare function useEmailFirst(): UseEmailFirstReturn;
|
|
685
|
+
|
|
686
|
+
export { type AppearanceProps, AuthCallback, type AuthCallbackProps, type AuthState, type AuthStatus, type LumoAuthContextValue, LumoAuthProvider, type LumoAuthProviderProps, type LumoAuthUser, Protect, type ProtectProps, RedirectToSignIn, type RedirectToSignInProps, SignIn, SignInButton, type SignInButtonProps, type SignInProps, SignOutButton, type SignOutButtonProps, SignUp, SignUpButton, type SignUpButtonProps, type SignUpProps, SignedIn, type SignedInProps, SignedOut, type SignedOutProps, type UseEmailFirstReturn, type UseMagicLinkReturn, UserAvatar, type UserAvatarProps, UserButton, type UserButtonProps, UserProfile, type UserProfileProps, useAbac, useAuth, useEmailFirst, useLumoAuth, useMagicLink, usePermission, useSession, useSignIn, useUser, useZanzibar };
|