@lumoauth/react 1.0.0 → 1.2.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/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { EmailCheckResult, TokenStorage, AbacCheckRequest, LumoAuth, ZanzibarCheckRequest } from '@lumoauth/client';
2
2
  export { LumoAuth, LumoAuthConfig } from '@lumoauth/client';
3
- import * as react from 'react';
4
- import react__default from 'react';
3
+ import * as React$1 from 'react';
4
+ import React__default from 'react';
5
5
 
6
6
  interface LumoAuthUser {
7
7
  /** Unique user ID */
@@ -57,6 +57,13 @@ interface LumoAuthProviderProps {
57
57
  authStrategy?: 'pkce' | 'password';
58
58
  /** OAuth redirect URI for the callback page (required for PKCE mode) */
59
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;
60
67
  /** URL to redirect after sign-in (defaults to current page) */
61
68
  afterSignInUrl?: string;
62
69
  /** URL to redirect after sign-up */
@@ -319,7 +326,7 @@ interface LumoAuthContextValue extends AuthState {
319
326
  };
320
327
  }
321
328
 
322
- declare function LumoAuthProvider({ domain, orgId, clientId, authStrategy, redirectUri, afterSignInUrl, afterSignUpUrl, afterSignOutUrl, storage, crossTab, children, }: LumoAuthProviderProps): react.JSX.Element;
329
+ declare function LumoAuthProvider({ domain, orgId, clientId, authStrategy, redirectUri, scope, afterSignInUrl, afterSignUpUrl, afterSignOutUrl, storage, crossTab, children, }: LumoAuthProviderProps): React$1.JSX.Element;
323
330
 
324
331
  /**
325
332
  * Drop-in sign-in component.
@@ -337,7 +344,7 @@ declare function LumoAuthProvider({ domain, orgId, clientId, authStrategy, redir
337
344
  * <SignIn afterSignInUrl="/dashboard" />
338
345
  * ```
339
346
  */
340
- declare function SignIn({ afterSignInUrl, signUpUrl, appearance, socialProviders, }: SignInProps): react__default.JSX.Element | null;
347
+ declare function SignIn({ afterSignInUrl, signUpUrl, appearance, socialProviders, }: SignInProps): React__default.JSX.Element | null;
341
348
 
342
349
  /**
343
350
  * Drop-in sign-up/registration component.
@@ -354,7 +361,7 @@ declare function SignIn({ afterSignInUrl, signUpUrl, appearance, socialProviders
354
361
  * <SignUp afterSignUpUrl="/onboarding" />
355
362
  * ```
356
363
  */
357
- declare function SignUp({ afterSignUpUrl, signInUrl, appearance, }: SignUpProps): react__default.JSX.Element | null;
364
+ declare function SignUp({ afterSignUpUrl, signInUrl, appearance, }: SignUpProps): React__default.JSX.Element | null;
358
365
 
359
366
  /**
360
367
  * Handles the OAuth callback after a PKCE redirect.
@@ -375,7 +382,7 @@ declare function SignUp({ afterSignUpUrl, signInUrl, appearance, }: SignUpProps)
375
382
  * }
376
383
  * ```
377
384
  */
378
- declare function AuthCallback({ afterSignInUrl, loading, error: errorComponent, }: AuthCallbackProps): react.JSX.Element;
385
+ declare function AuthCallback({ afterSignInUrl, loading, error: errorComponent, }: AuthCallbackProps): React$1.JSX.Element;
379
386
 
380
387
  /**
381
388
  * Clerk-style user avatar button with dropdown menu.
@@ -386,7 +393,7 @@ declare function AuthCallback({ afterSignInUrl, loading, error: errorComponent,
386
393
  * <UserButton afterSignOutUrl="/" />
387
394
  * ```
388
395
  */
389
- declare function UserButton({ afterSignOutUrl, showName, appearance, }: UserButtonProps): react__default.JSX.Element | null;
396
+ declare function UserButton({ afterSignOutUrl, showName, appearance, }: UserButtonProps): React__default.JSX.Element | null;
390
397
 
391
398
  /**
392
399
  * Renders the current user's avatar. Displays the profile image
@@ -406,7 +413,7 @@ declare function UserButton({ afterSignOutUrl, showName, appearance, }: UserButt
406
413
  * <UserAvatar shape="square" />
407
414
  * ```
408
415
  */
409
- declare function UserAvatar({ size, shape, appearance, }: UserAvatarProps): react__default.JSX.Element;
416
+ declare function UserAvatar({ size, shape, appearance, }: UserAvatarProps): React__default.JSX.Element;
410
417
 
411
418
  /**
412
419
  * Renders a user profile card showing account details, roles,
@@ -426,7 +433,7 @@ declare function UserAvatar({ size, shape, appearance, }: UserAvatarProps): reac
426
433
  * <UserProfile mode="compact" />
427
434
  * ```
428
435
  */
429
- declare function UserProfile({ afterSignOutUrl, mode, appearance, }: UserProfileProps): react__default.JSX.Element | null;
436
+ declare function UserProfile({ afterSignOutUrl, mode, appearance, }: UserProfileProps): React__default.JSX.Element | null;
430
437
 
431
438
  /**
432
439
  * Authorization gate component. Renders children only if the user
@@ -441,8 +448,9 @@ declare function UserProfile({ afterSignOutUrl, mode, appearance, }: UserProfile
441
448
  * <EditForm />
442
449
  * </Protect>
443
450
  *
444
- * // ReBAC (Zanzibar)
445
- * <Protect zanzibar={{ object: 'doc:123', relation: 'editor', subject: 'user:alice' }}>
451
+ * // ReBAC (Zanzibar). Without `subject`, the check is about the
452
+ * // signed-in user (`user:<sub>`).
453
+ * <Protect zanzibar={{ object: 'doc:123', relation: 'editor' }}>
446
454
  * <EditForm />
447
455
  * </Protect>
448
456
  *
@@ -452,7 +460,7 @@ declare function UserProfile({ afterSignOutUrl, mode, appearance, }: UserProfile
452
460
  * </Protect>
453
461
  * ```
454
462
  */
455
- declare function Protect({ permission, zanzibar, abac, fallback, children, }: ProtectProps): react__default.JSX.Element;
463
+ declare function Protect({ permission, zanzibar, abac, fallback, children, }: ProtectProps): React__default.JSX.Element;
456
464
 
457
465
  /**
458
466
  * Renders children only when the user is authenticated.
@@ -464,7 +472,7 @@ declare function Protect({ permission, zanzibar, abac, fallback, children, }: Pr
464
472
  * </SignedIn>
465
473
  * ```
466
474
  */
467
- declare function SignedIn({ children }: SignedInProps): react.JSX.Element | null;
475
+ declare function SignedIn({ children }: SignedInProps): React$1.JSX.Element | null;
468
476
  /**
469
477
  * Renders children only when the user is NOT authenticated.
470
478
  *
@@ -475,7 +483,7 @@ declare function SignedIn({ children }: SignedInProps): react.JSX.Element | null
475
483
  * </SignedOut>
476
484
  * ```
477
485
  */
478
- declare function SignedOut({ children }: SignedOutProps): react.JSX.Element | null;
486
+ declare function SignedOut({ children }: SignedOutProps): React$1.JSX.Element | null;
479
487
  /**
480
488
  * Unstyled button that triggers sign-in.
481
489
  * In PKCE mode, initiates the redirect flow.
@@ -488,7 +496,7 @@ declare function SignedOut({ children }: SignedOutProps): react.JSX.Element | nu
488
496
  * </SignInButton>
489
497
  * ```
490
498
  */
491
- declare function SignInButton({ children, signInUrl, className }: SignInButtonProps): react.JSX.Element;
499
+ declare function SignInButton({ children, signInUrl, className }: SignInButtonProps): React$1.JSX.Element;
492
500
  /**
493
501
  * Unstyled button that navigates to the sign-up page.
494
502
  *
@@ -499,7 +507,7 @@ declare function SignInButton({ children, signInUrl, className }: SignInButtonPr
499
507
  * </SignUpButton>
500
508
  * ```
501
509
  */
502
- declare function SignUpButton({ children, signUpUrl, className }: SignUpButtonProps): react.JSX.Element;
510
+ declare function SignUpButton({ children, signUpUrl, className }: SignUpButtonProps): React$1.JSX.Element;
503
511
  /**
504
512
  * Unstyled button that triggers sign-out.
505
513
  *
@@ -510,7 +518,7 @@ declare function SignUpButton({ children, signUpUrl, className }: SignUpButtonPr
510
518
  * </SignOutButton>
511
519
  * ```
512
520
  */
513
- declare function SignOutButton({ children, afterSignOutUrl, className }: SignOutButtonProps): react.JSX.Element;
521
+ declare function SignOutButton({ children, afterSignOutUrl, className }: SignOutButtonProps): React$1.JSX.Element;
514
522
  /**
515
523
  * Automatically redirects to the sign-in page when rendered.
516
524
  * Useful for protecting routes.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { EmailCheckResult, TokenStorage, AbacCheckRequest, LumoAuth, ZanzibarCheckRequest } from '@lumoauth/client';
2
2
  export { LumoAuth, LumoAuthConfig } from '@lumoauth/client';
3
- import * as react from 'react';
4
- import react__default from 'react';
3
+ import * as React$1 from 'react';
4
+ import React__default from 'react';
5
5
 
6
6
  interface LumoAuthUser {
7
7
  /** Unique user ID */
@@ -57,6 +57,13 @@ interface LumoAuthProviderProps {
57
57
  authStrategy?: 'pkce' | 'password';
58
58
  /** OAuth redirect URI for the callback page (required for PKCE mode) */
59
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;
60
67
  /** URL to redirect after sign-in (defaults to current page) */
61
68
  afterSignInUrl?: string;
62
69
  /** URL to redirect after sign-up */
@@ -319,7 +326,7 @@ interface LumoAuthContextValue extends AuthState {
319
326
  };
320
327
  }
321
328
 
322
- declare function LumoAuthProvider({ domain, orgId, clientId, authStrategy, redirectUri, afterSignInUrl, afterSignUpUrl, afterSignOutUrl, storage, crossTab, children, }: LumoAuthProviderProps): react.JSX.Element;
329
+ declare function LumoAuthProvider({ domain, orgId, clientId, authStrategy, redirectUri, scope, afterSignInUrl, afterSignUpUrl, afterSignOutUrl, storage, crossTab, children, }: LumoAuthProviderProps): React$1.JSX.Element;
323
330
 
324
331
  /**
325
332
  * Drop-in sign-in component.
@@ -337,7 +344,7 @@ declare function LumoAuthProvider({ domain, orgId, clientId, authStrategy, redir
337
344
  * <SignIn afterSignInUrl="/dashboard" />
338
345
  * ```
339
346
  */
340
- declare function SignIn({ afterSignInUrl, signUpUrl, appearance, socialProviders, }: SignInProps): react__default.JSX.Element | null;
347
+ declare function SignIn({ afterSignInUrl, signUpUrl, appearance, socialProviders, }: SignInProps): React__default.JSX.Element | null;
341
348
 
342
349
  /**
343
350
  * Drop-in sign-up/registration component.
@@ -354,7 +361,7 @@ declare function SignIn({ afterSignInUrl, signUpUrl, appearance, socialProviders
354
361
  * <SignUp afterSignUpUrl="/onboarding" />
355
362
  * ```
356
363
  */
357
- declare function SignUp({ afterSignUpUrl, signInUrl, appearance, }: SignUpProps): react__default.JSX.Element | null;
364
+ declare function SignUp({ afterSignUpUrl, signInUrl, appearance, }: SignUpProps): React__default.JSX.Element | null;
358
365
 
359
366
  /**
360
367
  * Handles the OAuth callback after a PKCE redirect.
@@ -375,7 +382,7 @@ declare function SignUp({ afterSignUpUrl, signInUrl, appearance, }: SignUpProps)
375
382
  * }
376
383
  * ```
377
384
  */
378
- declare function AuthCallback({ afterSignInUrl, loading, error: errorComponent, }: AuthCallbackProps): react.JSX.Element;
385
+ declare function AuthCallback({ afterSignInUrl, loading, error: errorComponent, }: AuthCallbackProps): React$1.JSX.Element;
379
386
 
380
387
  /**
381
388
  * Clerk-style user avatar button with dropdown menu.
@@ -386,7 +393,7 @@ declare function AuthCallback({ afterSignInUrl, loading, error: errorComponent,
386
393
  * <UserButton afterSignOutUrl="/" />
387
394
  * ```
388
395
  */
389
- declare function UserButton({ afterSignOutUrl, showName, appearance, }: UserButtonProps): react__default.JSX.Element | null;
396
+ declare function UserButton({ afterSignOutUrl, showName, appearance, }: UserButtonProps): React__default.JSX.Element | null;
390
397
 
391
398
  /**
392
399
  * Renders the current user's avatar. Displays the profile image
@@ -406,7 +413,7 @@ declare function UserButton({ afterSignOutUrl, showName, appearance, }: UserButt
406
413
  * <UserAvatar shape="square" />
407
414
  * ```
408
415
  */
409
- declare function UserAvatar({ size, shape, appearance, }: UserAvatarProps): react__default.JSX.Element;
416
+ declare function UserAvatar({ size, shape, appearance, }: UserAvatarProps): React__default.JSX.Element;
410
417
 
411
418
  /**
412
419
  * Renders a user profile card showing account details, roles,
@@ -426,7 +433,7 @@ declare function UserAvatar({ size, shape, appearance, }: UserAvatarProps): reac
426
433
  * <UserProfile mode="compact" />
427
434
  * ```
428
435
  */
429
- declare function UserProfile({ afterSignOutUrl, mode, appearance, }: UserProfileProps): react__default.JSX.Element | null;
436
+ declare function UserProfile({ afterSignOutUrl, mode, appearance, }: UserProfileProps): React__default.JSX.Element | null;
430
437
 
431
438
  /**
432
439
  * Authorization gate component. Renders children only if the user
@@ -441,8 +448,9 @@ declare function UserProfile({ afterSignOutUrl, mode, appearance, }: UserProfile
441
448
  * <EditForm />
442
449
  * </Protect>
443
450
  *
444
- * // ReBAC (Zanzibar)
445
- * <Protect zanzibar={{ object: 'doc:123', relation: 'editor', subject: 'user:alice' }}>
451
+ * // ReBAC (Zanzibar). Without `subject`, the check is about the
452
+ * // signed-in user (`user:<sub>`).
453
+ * <Protect zanzibar={{ object: 'doc:123', relation: 'editor' }}>
446
454
  * <EditForm />
447
455
  * </Protect>
448
456
  *
@@ -452,7 +460,7 @@ declare function UserProfile({ afterSignOutUrl, mode, appearance, }: UserProfile
452
460
  * </Protect>
453
461
  * ```
454
462
  */
455
- declare function Protect({ permission, zanzibar, abac, fallback, children, }: ProtectProps): react__default.JSX.Element;
463
+ declare function Protect({ permission, zanzibar, abac, fallback, children, }: ProtectProps): React__default.JSX.Element;
456
464
 
457
465
  /**
458
466
  * Renders children only when the user is authenticated.
@@ -464,7 +472,7 @@ declare function Protect({ permission, zanzibar, abac, fallback, children, }: Pr
464
472
  * </SignedIn>
465
473
  * ```
466
474
  */
467
- declare function SignedIn({ children }: SignedInProps): react.JSX.Element | null;
475
+ declare function SignedIn({ children }: SignedInProps): React$1.JSX.Element | null;
468
476
  /**
469
477
  * Renders children only when the user is NOT authenticated.
470
478
  *
@@ -475,7 +483,7 @@ declare function SignedIn({ children }: SignedInProps): react.JSX.Element | null
475
483
  * </SignedOut>
476
484
  * ```
477
485
  */
478
- declare function SignedOut({ children }: SignedOutProps): react.JSX.Element | null;
486
+ declare function SignedOut({ children }: SignedOutProps): React$1.JSX.Element | null;
479
487
  /**
480
488
  * Unstyled button that triggers sign-in.
481
489
  * In PKCE mode, initiates the redirect flow.
@@ -488,7 +496,7 @@ declare function SignedOut({ children }: SignedOutProps): react.JSX.Element | nu
488
496
  * </SignInButton>
489
497
  * ```
490
498
  */
491
- declare function SignInButton({ children, signInUrl, className }: SignInButtonProps): react.JSX.Element;
499
+ declare function SignInButton({ children, signInUrl, className }: SignInButtonProps): React$1.JSX.Element;
492
500
  /**
493
501
  * Unstyled button that navigates to the sign-up page.
494
502
  *
@@ -499,7 +507,7 @@ declare function SignInButton({ children, signInUrl, className }: SignInButtonPr
499
507
  * </SignUpButton>
500
508
  * ```
501
509
  */
502
- declare function SignUpButton({ children, signUpUrl, className }: SignUpButtonProps): react.JSX.Element;
510
+ declare function SignUpButton({ children, signUpUrl, className }: SignUpButtonProps): React$1.JSX.Element;
503
511
  /**
504
512
  * Unstyled button that triggers sign-out.
505
513
  *
@@ -510,7 +518,7 @@ declare function SignUpButton({ children, signUpUrl, className }: SignUpButtonPr
510
518
  * </SignOutButton>
511
519
  * ```
512
520
  */
513
- declare function SignOutButton({ children, afterSignOutUrl, className }: SignOutButtonProps): react.JSX.Element;
521
+ declare function SignOutButton({ children, afterSignOutUrl, className }: SignOutButtonProps): React$1.JSX.Element;
514
522
  /**
515
523
  * Automatically redirects to the sign-in page when rendered.
516
524
  * Useful for protecting routes.
package/dist/index.js CHANGED
@@ -933,12 +933,14 @@ function parseUserFromUserInfo(data) {
933
933
  claims: data
934
934
  };
935
935
  }
936
+ var DEFAULT_SCOPE = "openid profile email";
936
937
  function LumoAuthProvider({
937
938
  domain,
938
939
  orgId,
939
940
  clientId,
940
941
  authStrategy = "pkce",
941
942
  redirectUri,
943
+ scope = DEFAULT_SCOPE,
942
944
  afterSignInUrl,
943
945
  afterSignUpUrl,
944
946
  afterSignOutUrl,
@@ -1025,18 +1027,18 @@ function LumoAuthProvider({
1025
1027
  const signInWithRedirect = (0, import_react.useCallback)(() => {
1026
1028
  authModule.buildAuthorizationUrl({
1027
1029
  redirectUri: resolvedRedirectUri,
1028
- scope: "openid profile email"
1030
+ scope
1029
1031
  }).then(({ url, codeVerifier, state: stateParam }) => {
1030
1032
  savePkceParams(codeVerifier, stateParam);
1031
1033
  if (typeof window !== "undefined") {
1032
1034
  window.location.href = url;
1033
1035
  }
1034
1036
  });
1035
- }, [authModule, resolvedRedirectUri]);
1037
+ }, [authModule, resolvedRedirectUri, scope]);
1036
1038
  const signInWithSocial = (0, import_react.useCallback)((provider) => {
1037
1039
  authModule.buildAuthorizationUrl({
1038
1040
  redirectUri: resolvedRedirectUri,
1039
- scope: "openid profile email",
1041
+ scope,
1040
1042
  extraParams: { provider }
1041
1043
  }).then(({ url, codeVerifier, state: stateParam }) => {
1042
1044
  savePkceParams(codeVerifier, stateParam);
@@ -1044,7 +1046,7 @@ function LumoAuthProvider({
1044
1046
  window.location.href = url;
1045
1047
  }
1046
1048
  });
1047
- }, [authModule, resolvedRedirectUri]);
1049
+ }, [authModule, resolvedRedirectUri, scope]);
1048
1050
  const signIn = (0, import_react.useCallback)(async (email, password) => {
1049
1051
  if (authStrategy === "pkce" || !email && !password) {
1050
1052
  signInWithRedirect();
@@ -1058,7 +1060,7 @@ function LumoAuthProvider({
1058
1060
  const data = await authModule.passwordGrant(
1059
1061
  email,
1060
1062
  password,
1061
- "openid profile email",
1063
+ scope,
1062
1064
  redirectUri
1063
1065
  );
1064
1066
  await session.adopt(data);
@@ -1068,7 +1070,7 @@ function LumoAuthProvider({
1068
1070
  dispatch({ type: "ERROR", error: err instanceof Error ? err.message : "Sign in failed" });
1069
1071
  throw err;
1070
1072
  }
1071
- }, [authStrategy, authModule, redirectUri, fetchUser, session, signInWithRedirect, dispatch]);
1073
+ }, [authStrategy, authModule, redirectUri, scope, fetchUser, session, signInWithRedirect, dispatch]);
1072
1074
  const handleCallback = (0, import_react.useCallback)(async () => {
1073
1075
  if (typeof window === "undefined") return;
1074
1076
  const params = new URLSearchParams(window.location.search);
@@ -1133,7 +1135,7 @@ function LumoAuthProvider({
1133
1135
  client_id: clientId,
1134
1136
  redirect_uri: resolvedRedirectUri,
1135
1137
  response_type: "code",
1136
- scope: "openid profile email"
1138
+ scope
1137
1139
  }).toString();
1138
1140
  if (typeof window !== "undefined") {
1139
1141
  window.location.href = signUpUrl;
@@ -1147,7 +1149,7 @@ function LumoAuthProvider({
1147
1149
  throw new Error(
1148
1150
  `Inline registration is not supported by this LumoAuth server: there is no JSON registration endpoint. Use redirectToSignUp() to send the user to the hosted registration page (${domain.replace(/\/+$/, "")}/orgs/${encodeURIComponent(orgId)}/register), or set authStrategy: "pkce".`
1149
1151
  );
1150
- }, [authStrategy, domain, orgId, clientId, resolvedRedirectUri, signIn]);
1152
+ }, [authStrategy, domain, orgId, clientId, resolvedRedirectUri, scope, signIn]);
1151
1153
  const sendMagicLink = (0, import_react.useCallback)(async (email, redirectUri2) => {
1152
1154
  await authModule.requestMagicLink({ email, redirectUri: redirectUri2 });
1153
1155
  }, [authModule]);
@@ -2274,7 +2276,7 @@ function Protect({
2274
2276
  fallback = null,
2275
2277
  children
2276
2278
  }) {
2277
- const { isLoaded, isSignedIn } = useLumoAuthContext();
2279
+ const { isLoaded, isSignedIn, user } = useLumoAuthContext();
2278
2280
  if (permission) {
2279
2281
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2280
2282
  ProtectWithPermission,
@@ -2295,6 +2297,7 @@ function Protect({
2295
2297
  fallback,
2296
2298
  isLoaded,
2297
2299
  isSignedIn,
2300
+ user,
2298
2301
  children
2299
2302
  }
2300
2303
  );
@@ -2332,25 +2335,49 @@ function ProtectWithPermission({
2332
2335
  }
2333
2336
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children });
2334
2337
  }
2338
+ function resolveZanzibarSubject(explicit, user) {
2339
+ if (explicit) return explicit;
2340
+ const sub = user?.sub || user?.id;
2341
+ return sub ? `user:${sub}` : null;
2342
+ }
2335
2343
  function ProtectWithZanzibar({
2336
2344
  zanzibar,
2337
2345
  fallback,
2338
2346
  isLoaded,
2339
2347
  isSignedIn,
2348
+ user,
2340
2349
  children
2341
2350
  }) {
2342
- const { allowed, isLoading } = useZanzibar({
2343
- object: zanzibar.object,
2344
- relation: zanzibar.relation,
2345
- subject: zanzibar.subject || "user:me"
2346
- });
2347
- if (!isLoaded || isLoading) {
2351
+ if (!isLoaded) {
2348
2352
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "la-protect-loading", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "la-spinner" }) });
2349
2353
  }
2350
- if (!isSignedIn || !allowed) {
2354
+ const subject = isSignedIn ? resolveZanzibarSubject(zanzibar.subject, user) : null;
2355
+ if (!subject) {
2351
2356
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: fallback });
2352
2357
  }
2353
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children });
2358
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2359
+ ZanzibarCheck,
2360
+ {
2361
+ object: zanzibar.object,
2362
+ relation: zanzibar.relation,
2363
+ subject,
2364
+ fallback,
2365
+ children
2366
+ }
2367
+ );
2368
+ }
2369
+ function ZanzibarCheck({
2370
+ object,
2371
+ relation,
2372
+ subject,
2373
+ fallback,
2374
+ children
2375
+ }) {
2376
+ const { allowed, isLoading } = useZanzibar({ object, relation, subject });
2377
+ if (isLoading) {
2378
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "la-protect-loading", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "la-spinner" }) });
2379
+ }
2380
+ return allowed ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: fallback });
2354
2381
  }
2355
2382
  function ProtectWithAbac({
2356
2383
  abac,