@stackframe/react 2.8.54 → 2.8.58

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.
Files changed (74) hide show
  1. package/dist/components/credential-sign-up.js.map +1 -1
  2. package/dist/components/user-button.js +4 -4
  3. package/dist/components/user-button.js.map +1 -1
  4. package/dist/components-page/account-settings/email-and-auth/emails-section.js +4 -3
  5. package/dist/components-page/account-settings/email-and-auth/emails-section.js.map +1 -1
  6. package/dist/components-page/onboarding.js +170 -0
  7. package/dist/components-page/onboarding.js.map +1 -0
  8. package/dist/components-page/stack-handler-client.js +13 -1
  9. package/dist/components-page/stack-handler-client.js.map +1 -1
  10. package/dist/components-page/stack-handler.js.map +1 -1
  11. package/dist/components-page/team-invitation.js +15 -1
  12. package/dist/components-page/team-invitation.js.map +1 -1
  13. package/dist/esm/components/credential-sign-up.js.map +1 -1
  14. package/dist/esm/components/user-button.js +4 -4
  15. package/dist/esm/components/user-button.js.map +1 -1
  16. package/dist/esm/components-page/account-settings/email-and-auth/emails-section.js +4 -3
  17. package/dist/esm/components-page/account-settings/email-and-auth/emails-section.js.map +1 -1
  18. package/dist/esm/components-page/onboarding.js +146 -0
  19. package/dist/esm/components-page/onboarding.js.map +1 -0
  20. package/dist/esm/components-page/stack-handler-client.js +13 -1
  21. package/dist/esm/components-page/stack-handler-client.js.map +1 -1
  22. package/dist/esm/components-page/stack-handler.js.map +1 -1
  23. package/dist/esm/components-page/team-invitation.js +15 -1
  24. package/dist/esm/components-page/team-invitation.js.map +1 -1
  25. package/dist/esm/generated/global-css.js +1 -1
  26. package/dist/esm/generated/global-css.js.map +1 -1
  27. package/dist/esm/lib/cookie.js +50 -15
  28. package/dist/esm/lib/cookie.js.map +1 -1
  29. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +235 -0
  30. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
  31. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js +154 -31
  32. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
  33. package/dist/esm/lib/stack-app/apps/implementations/common.js +2 -1
  34. package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -1
  35. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +40 -27
  36. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
  37. package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
  38. package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
  39. package/dist/esm/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
  40. package/dist/esm/lib/stack-app/common.js.map +1 -1
  41. package/dist/esm/lib/stack-app/index.js.map +1 -1
  42. package/dist/esm/lib/stack-app/projects/index.js +4 -0
  43. package/dist/esm/lib/stack-app/projects/index.js.map +1 -1
  44. package/dist/esm/lib/stack-app/teams/index.js.map +1 -1
  45. package/dist/esm/lib/stack-app/users/index.js +13 -12
  46. package/dist/esm/lib/stack-app/users/index.js.map +1 -1
  47. package/dist/generated/global-css.js +1 -1
  48. package/dist/generated/global-css.js.map +1 -1
  49. package/dist/index.d.mts +269 -16
  50. package/dist/index.d.ts +269 -16
  51. package/dist/lib/cookie.js +50 -15
  52. package/dist/lib/cookie.js.map +1 -1
  53. package/dist/lib/stack-app/apps/implementations/admin-app-impl.js +235 -0
  54. package/dist/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
  55. package/dist/lib/stack-app/apps/implementations/client-app-impl.js +151 -28
  56. package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
  57. package/dist/lib/stack-app/apps/implementations/common.js +2 -1
  58. package/dist/lib/stack-app/apps/implementations/common.js.map +1 -1
  59. package/dist/lib/stack-app/apps/implementations/server-app-impl.js +38 -25
  60. package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
  61. package/dist/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
  62. package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
  63. package/dist/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
  64. package/dist/lib/stack-app/common.js.map +1 -1
  65. package/dist/lib/stack-app/email/index.js.map +1 -1
  66. package/dist/lib/stack-app/index.js.map +1 -1
  67. package/dist/lib/stack-app/project-configs/index.js.map +1 -1
  68. package/dist/lib/stack-app/projects/index.js +4 -0
  69. package/dist/lib/stack-app/projects/index.js.map +1 -1
  70. package/dist/lib/stack-app/teams/index.js.map +1 -1
  71. package/dist/lib/stack-app/users/index.js +15 -14
  72. package/dist/lib/stack-app/users/index.js.map +1 -1
  73. package/package.json +4 -3
  74. package/CHANGELOG.md +0 -2052
@@ -39,6 +39,7 @@ var import_sessions = require("@stackframe/stack-shared/dist/sessions");
39
39
  var import_bytes = require("@stackframe/stack-shared/dist/utils/bytes");
40
40
  var import_env = require("@stackframe/stack-shared/dist/utils/env");
41
41
  var import_errors = require("@stackframe/stack-shared/dist/utils/errors");
42
+ var import_json = require("@stackframe/stack-shared/dist/utils/json");
42
43
  var import_maps = require("@stackframe/stack-shared/dist/utils/maps");
43
44
  var import_objects = require("@stackframe/stack-shared/dist/utils/objects");
44
45
  var import_promises = require("@stackframe/stack-shared/dist/utils/promises");
@@ -60,7 +61,6 @@ var import_projects = require("../../projects/index.js");
60
61
  var import_teams = require("../../teams/index.js");
61
62
  var import_users = require("../../users/index.js");
62
63
  var import_common2 = require("./common.js");
63
- var import_json = require("@stackframe/stack-shared/dist/utils/json");
64
64
  var import_common3 = require("./common.js");
65
65
  var isReactServer = false;
66
66
  var process = globalThis.process ?? { env: {} };
@@ -494,9 +494,10 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
494
494
  return;
495
495
  }
496
496
  const domain = await this._trustedParentDomainCache.getOrWait([hostname], "read-write");
497
+ const cookieOptions = { maxAge: 60 * 60 * 24 * 365, noOpIfServerComponent: true };
497
498
  const setCookie = async (targetDomain, value2) => {
498
499
  const name = this._getCustomRefreshCookieName(targetDomain);
499
- const options = { maxAge: 60 * 60 * 24 * 365, domain: targetDomain, noOpIfServerComponent: true };
500
+ const options = { ...cookieOptions, domain: targetDomain };
500
501
  if (context === "browser") {
501
502
  (0, import_cookie.setOrDeleteCookieClient)(name, value2, options);
502
503
  } else {
@@ -509,7 +510,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
509
510
  const value = refreshToken && updatedAt ? this._formatRefreshCookieValue(refreshToken, updatedAt) : null;
510
511
  await setCookie(domain.data, value);
511
512
  const isSecure = await (0, import_cookie.isSecure)();
512
- await (0, import_cookie.setOrDeleteCookie)(this._getRefreshTokenDefaultCookieNameForSecure(isSecure), null);
513
+ await (0, import_cookie.setOrDeleteCookie)(this._getRefreshTokenDefaultCookieNameForSecure(isSecure), null, cookieOptions);
513
514
  });
514
515
  }
515
516
  async _getTrustedParentDomain(currentDomain) {
@@ -561,7 +562,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
561
562
  );
562
563
  (0, import_cookie.setOrDeleteCookieClient)(defaultName, refreshCookieValue, { maxAge: 60 * 60 * 24 * 365, secure });
563
564
  (0, import_cookie.setOrDeleteCookieClient)(this._accessTokenCookieName, accessTokenPayload, { maxAge: 60 * 60 * 24 });
564
- cookieNamesToDelete.forEach((name) => (0, import_cookie.deleteCookieClient)(name));
565
+ cookieNamesToDelete.forEach((name) => (0, import_cookie.deleteCookieClient)(name, {}));
565
566
  this._queueCustomRefreshCookieUpdate(refreshToken, updatedAt, "browser");
566
567
  hasSucceededInWriting = true;
567
568
  } catch (e) {
@@ -605,7 +606,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
605
606
  if (cookieNamesToDelete.length > 0) {
606
607
  await Promise.all(
607
608
  cookieNamesToDelete.map(
608
- (name) => (0, import_cookie.setOrDeleteCookie)(name, null, { noOpIfServerComponent: true })
609
+ (name) => (0, import_cookie.deleteCookie)(name, { noOpIfServerComponent: true })
609
610
  )
610
611
  );
611
612
  }
@@ -970,22 +971,65 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
970
971
  _internalSession: session,
971
972
  currentSession: {
972
973
  async getTokens() {
973
- const tokens = await session.getOrFetchLikelyValidTokens(2e4);
974
+ const tokens = await session.getOrFetchLikelyValidTokens(2e4, 75e3);
974
975
  return {
975
976
  accessToken: tokens?.accessToken.token ?? null,
976
977
  refreshToken: tokens?.refreshToken?.token ?? null
977
978
  };
979
+ },
980
+ useTokens() {
981
+ const [_, setCounter] = import_react2.default.useState(0);
982
+ import_react2.default.useEffect(() => {
983
+ const { unsubscribe: unsubscribeRefresh } = session.startRefreshingAccessToken(3e4, 6e4);
984
+ const { unsubscribe: unsubscribeInvalidate } = session.onInvalidate(() => setCounter((c) => c + 1));
985
+ const { unsubscribe: unsubscribeAccessTokenChange } = session.onAccessTokenChange(() => setCounter((c) => c + 1));
986
+ return () => {
987
+ unsubscribeRefresh();
988
+ unsubscribeInvalidate();
989
+ unsubscribeAccessTokenChange();
990
+ };
991
+ }, []);
992
+ let accessToken = session.isKnownToBeInvalid() ? null : session.getAccessTokenIfNotExpiredYet(2e4, 75e3);
993
+ if (accessToken === null) {
994
+ accessToken = (0, import_react.use)(session.getOrFetchLikelyValidTokens(2e4, 75e3))?.accessToken ?? null;
995
+ }
996
+ return {
997
+ accessToken: accessToken?.token ?? null,
998
+ refreshToken: session.getRefreshToken()?.token ?? null
999
+ };
978
1000
  }
979
1001
  },
1002
+ async getAccessToken() {
1003
+ const tokens = await this.currentSession.getTokens();
1004
+ return tokens.accessToken;
1005
+ },
1006
+ useAccessToken() {
1007
+ return this.currentSession.useTokens().accessToken;
1008
+ },
1009
+ async getRefreshToken() {
1010
+ const tokens = await this.currentSession.getTokens();
1011
+ return tokens.refreshToken;
1012
+ },
1013
+ useRefreshToken() {
1014
+ return this.currentSession.useTokens().refreshToken;
1015
+ },
980
1016
  async getAuthHeaders() {
981
1017
  return {
982
1018
  "x-stack-auth": JSON.stringify(await this.getAuthJson())
983
1019
  };
984
1020
  },
1021
+ useAuthHeaders() {
1022
+ return {
1023
+ "x-stack-auth": JSON.stringify(this.useAuthJson())
1024
+ };
1025
+ },
985
1026
  async getAuthJson() {
986
1027
  const tokens = await this.currentSession.getTokens();
987
1028
  return tokens;
988
1029
  },
1030
+ useAuthJson() {
1031
+ return this.currentSession.useTokens();
1032
+ },
989
1033
  signOut(options) {
990
1034
  return app._signOut(session, options);
991
1035
  }
@@ -1026,6 +1070,8 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1026
1070
  passkeyAuthEnabled: crud.passkey_auth_enabled,
1027
1071
  isMultiFactorRequired: crud.requires_totp_mfa,
1028
1072
  isAnonymous: crud.is_anonymous,
1073
+ isRestricted: crud.is_restricted,
1074
+ restrictedReason: crud.restricted_reason,
1029
1075
  toClientJson() {
1030
1076
  return crud;
1031
1077
  }
@@ -1056,7 +1102,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1056
1102
  return this.update({ clientMetadata: metadata });
1057
1103
  },
1058
1104
  async setSelectedTeam(team) {
1059
- await this.update({ selectedTeamId: team?.id ?? null });
1105
+ await this.update({ selectedTeamId: typeof team === "string" ? team : team?.id ?? null });
1060
1106
  },
1061
1107
  getConnectedAccount,
1062
1108
  useConnectedAccount,
@@ -1336,6 +1382,25 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1336
1382
  const response = import_results.Result.orThrow(await this._customProductsCache.getOrWait([session, options.customCustomerId, options.cursor ?? null, options.limit ?? null], "write-only"));
1337
1383
  return this._customerProductsFromResponse(response);
1338
1384
  }
1385
+ async cancelSubscription(options) {
1386
+ const session = await this._getSession();
1387
+ const user = await this.getUser();
1388
+ if (!user) {
1389
+ throw new import_stack_shared.KnownErrors.UserAuthenticationRequired();
1390
+ }
1391
+ const customerType = "teamId" in options ? "team" : "user";
1392
+ const customerId = "teamId" in options ? options.teamId : user.id;
1393
+ await this._interface.cancelSubscription({
1394
+ customer_type: customerType,
1395
+ customer_id: customerId,
1396
+ product_id: options.productId
1397
+ }, session);
1398
+ if (customerType === "user") {
1399
+ await this._userProductsCache.invalidateWhere(([cachedSession, userId]) => cachedSession === session && userId === customerId);
1400
+ } else {
1401
+ await this._teamProductsCache.invalidateWhere(([cachedSession, teamId]) => cachedSession === session && teamId === customerId);
1402
+ }
1403
+ }
1339
1404
  useProducts(options) {
1340
1405
  const session = this._useSession();
1341
1406
  const cache = "userId" in options ? this._userProductsCache : "teamId" in options ? this._teamProductsCache : this._customProductsCache;
@@ -1345,15 +1410,13 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1345
1410
  return this._customerProductsFromResponse(response);
1346
1411
  }
1347
1412
  _currentUserFromCrud(crud, session) {
1348
- const currentUser = {
1413
+ const currentUser = (0, import_users.withUserDestructureGuard)({
1349
1414
  ...this._createBaseUser(crud),
1350
1415
  ...this._createAuth(session),
1351
1416
  ...this._createUserExtraFromCurrent(crud, session),
1352
1417
  ...this._isInternalProject() ? this._createInternalUserExtra(session) : {},
1353
1418
  ...this._createCustomer(crud.id, "user", session)
1354
- };
1355
- (0, import_users.attachUserDestructureGuard)(currentUser);
1356
- Object.freeze(currentUser);
1419
+ });
1357
1420
  return currentUser;
1358
1421
  }
1359
1422
  _clientSessionFromCrud(crud) {
@@ -1436,7 +1499,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1436
1499
  const queryParams = new URLSearchParams(window.location.search);
1437
1500
  url = queryParams.get("after_auth_return_to") || url;
1438
1501
  }
1439
- } else if (handlerName === "signIn" || handlerName === "signUp") {
1502
+ } else if (handlerName === "signIn" || handlerName === "signUp" || handlerName === "onboarding") {
1440
1503
  if (isReactServer || typeof window === "undefined") {
1441
1504
  } else {
1442
1505
  const currentUrl = new URL(window.location.href);
@@ -1485,6 +1548,9 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1485
1548
  async redirectToAfterSignUp(options) {
1486
1549
  return await this._redirectToHandler("afterSignUp", options);
1487
1550
  }
1551
+ async redirectToOnboarding(options) {
1552
+ return await this._redirectToHandler("onboarding", options);
1553
+ }
1488
1554
  async redirectToAfterSignOut(options) {
1489
1555
  return await this._redirectToHandler("afterSignOut", options);
1490
1556
  }
@@ -1550,16 +1616,22 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1550
1616
  return result;
1551
1617
  }
1552
1618
  async getUser(options) {
1619
+ if (options?.or === "anonymous" && options.includeRestricted === false) {
1620
+ throw new Error("Cannot use { or: 'anonymous' } with { includeRestricted: false }. Anonymous users implicitly include restricted users.");
1621
+ }
1553
1622
  this._ensurePersistentTokenStore(options?.tokenStore);
1554
1623
  const session = await this._getSession(options?.tokenStore);
1555
1624
  let crud = import_results.Result.orThrow(await this._currentUserCache.getOrWait([session], "write-only"));
1556
- if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists[deprecated]") {
1557
- crud = null;
1558
- }
1559
- if (crud === null) {
1625
+ const includeAnonymous = options?.or === "anonymous" || options?.or === "anonymous-if-exists[deprecated]";
1626
+ const includeRestricted = options?.includeRestricted === true || includeAnonymous;
1627
+ if (crud === null || crud.is_anonymous && !includeAnonymous || crud.is_restricted && !includeRestricted) {
1560
1628
  switch (options?.or) {
1561
1629
  case "redirect": {
1562
- await this.redirectToSignIn({ replace: true });
1630
+ if (!crud?.is_anonymous && crud?.is_restricted) {
1631
+ await this.redirectToOnboarding({ replace: true });
1632
+ } else {
1633
+ await this.redirectToSignIn({ replace: true });
1634
+ }
1563
1635
  break;
1564
1636
  }
1565
1637
  case "throw": {
@@ -1567,7 +1639,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1567
1639
  }
1568
1640
  case "anonymous": {
1569
1641
  const tokens = await this._signUpAnonymously();
1570
- return await this.getUser({ tokenStore: tokens, or: "anonymous-if-exists[deprecated]" }) ?? (0, import_errors.throwErr)("Something went wrong while signing up anonymously");
1642
+ return await this.getUser({ tokenStore: tokens, or: "anonymous-if-exists[deprecated]", includeRestricted: true }) ?? (0, import_errors.throwErr)("Something went wrong while signing up anonymously");
1571
1643
  }
1572
1644
  case void 0:
1573
1645
  case "anonymous-if-exists[deprecated]":
@@ -1579,16 +1651,22 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1579
1651
  return crud && this._currentUserFromCrud(crud, session);
1580
1652
  }
1581
1653
  useUser(options) {
1654
+ if (options?.or === "anonymous" && options.includeRestricted === false) {
1655
+ throw new Error("Cannot use { or: 'anonymous' } with { includeRestricted: false }. Anonymous users implicitly include restricted users.");
1656
+ }
1582
1657
  this._ensurePersistentTokenStore(options?.tokenStore);
1583
1658
  const session = this._useSession(options?.tokenStore);
1584
1659
  let crud = (0, import_common3.useAsyncCache)(this._currentUserCache, [session], "clientApp.useUser()");
1585
- if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists[deprecated]") {
1586
- crud = null;
1587
- }
1588
- if (crud === null) {
1660
+ const includeAnonymous = options?.or === "anonymous" || options?.or === "anonymous-if-exists[deprecated]";
1661
+ const includeRestricted = options?.includeRestricted === true || includeAnonymous;
1662
+ if (crud === null || crud.is_anonymous && !includeAnonymous || crud.is_restricted && !includeRestricted) {
1589
1663
  switch (options?.or) {
1590
1664
  case "redirect": {
1591
- (0, import_promises.runAsynchronously)(this.redirectToSignIn({ replace: true }));
1665
+ if (!crud?.is_anonymous && crud?.is_restricted) {
1666
+ (0, import_promises.runAsynchronously)(this.redirectToOnboarding({ replace: true }));
1667
+ } else {
1668
+ (0, import_promises.runAsynchronously)(this.redirectToSignIn({ replace: true }));
1669
+ }
1592
1670
  (0, import_react.suspend)();
1593
1671
  throw new import_errors.StackAssertionError("suspend should never return");
1594
1672
  }
@@ -1616,7 +1694,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1616
1694
  }, [crud, session, options?.or]);
1617
1695
  }
1618
1696
  _getTokenPartialUserFromSession(session, options) {
1619
- const accessToken = session.getAccessTokenIfNotExpiredYet(0);
1697
+ const accessToken = session.getAccessTokenIfNotExpiredYet(0, null);
1620
1698
  if (!accessToken) {
1621
1699
  return null;
1622
1700
  }
@@ -1629,7 +1707,9 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1629
1707
  primaryEmail: accessToken.payload.email,
1630
1708
  displayName: accessToken.payload.name,
1631
1709
  primaryEmailVerified: accessToken.payload.email_verified,
1632
- isAnonymous
1710
+ isAnonymous,
1711
+ isRestricted: accessToken.payload.is_restricted,
1712
+ restrictedReason: accessToken.payload.restricted_reason
1633
1713
  };
1634
1714
  }
1635
1715
  async _getPartialUserFromConvex(ctx) {
@@ -1642,7 +1722,9 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1642
1722
  displayName: auth.name ?? null,
1643
1723
  primaryEmail: auth.email ?? null,
1644
1724
  primaryEmailVerified: auth.email_verified,
1645
- isAnonymous: auth.is_anonymous
1725
+ isAnonymous: auth.is_anonymous,
1726
+ isRestricted: auth.is_restricted,
1727
+ restrictedReason: auth.restricted_reason ?? null
1646
1728
  };
1647
1729
  }
1648
1730
  async getPartialUser(options) {
@@ -1680,7 +1762,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1680
1762
  return async (args) => {
1681
1763
  const session = await this._getSession(options.tokenStore ?? this._tokenStoreInit);
1682
1764
  if (!args.forceRefreshToken) {
1683
- const tokens2 = await session.getOrFetchLikelyValidTokens(2e4);
1765
+ const tokens2 = await session.getOrFetchLikelyValidTokens(2e4, 75e3);
1684
1766
  return tokens2?.accessToken.token ?? null;
1685
1767
  }
1686
1768
  const tokens = await session.fetchNewTokens();
@@ -1689,7 +1771,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1689
1771
  }
1690
1772
  async getConvexHttpClientAuth(options) {
1691
1773
  const session = await this._getSession(options.tokenStore);
1692
- const tokens = await session.getOrFetchLikelyValidTokens(2e4);
1774
+ const tokens = await session.getOrFetchLikelyValidTokens(2e4, 75e3);
1693
1775
  return tokens?.accessToken.token ?? "";
1694
1776
  }
1695
1777
  async _updateClientUser(update, session) {
@@ -2036,11 +2118,44 @@ ${url}`);
2036
2118
  await user.signOut({ redirectUrl: options?.redirectUrl });
2037
2119
  }
2038
2120
  }
2121
+ async getAccessToken(options) {
2122
+ const user = await this.getUser({ tokenStore: options?.tokenStore ?? void 0 });
2123
+ if (user) {
2124
+ return await user.getAccessToken();
2125
+ }
2126
+ return null;
2127
+ }
2128
+ useAccessToken(options) {
2129
+ const user = this.useUser({ tokenStore: options?.tokenStore ?? void 0 });
2130
+ if (user) {
2131
+ return user.useAccessToken();
2132
+ }
2133
+ return null;
2134
+ }
2135
+ async getRefreshToken(options) {
2136
+ const user = await this.getUser({ tokenStore: options?.tokenStore ?? void 0 });
2137
+ if (user) {
2138
+ return await user.getRefreshToken();
2139
+ }
2140
+ return null;
2141
+ }
2142
+ useRefreshToken(options) {
2143
+ const user = this.useUser({ tokenStore: options?.tokenStore ?? void 0 });
2144
+ if (user) {
2145
+ return user.useRefreshToken();
2146
+ }
2147
+ return null;
2148
+ }
2039
2149
  async getAuthHeaders(options) {
2040
2150
  return {
2041
2151
  "x-stack-auth": JSON.stringify(await this.getAuthJson(options))
2042
2152
  };
2043
2153
  }
2154
+ useAuthHeaders(options) {
2155
+ return {
2156
+ "x-stack-auth": JSON.stringify(this.useAuthJson(options))
2157
+ };
2158
+ }
2044
2159
  async getAuthJson(options) {
2045
2160
  const user = await this.getUser({ tokenStore: options?.tokenStore ?? void 0 });
2046
2161
  if (user) {
@@ -2048,6 +2163,13 @@ ${url}`);
2048
2163
  }
2049
2164
  return { accessToken: null, refreshToken: null };
2050
2165
  }
2166
+ useAuthJson(options) {
2167
+ const user = this.useUser({ tokenStore: options?.tokenStore ?? void 0 });
2168
+ if (user) {
2169
+ return user.useAuthJson();
2170
+ }
2171
+ return { accessToken: null, refreshToken: null };
2172
+ }
2051
2173
  async getProject() {
2052
2174
  const crud = import_results.Result.orThrow(await this._currentProjectCache.getOrWait([], "write-only"));
2053
2175
  return this._clientProjectFromCrud(crud);
@@ -2084,6 +2206,7 @@ ${url}`);
2084
2206
  }
2085
2207
  async _refreshUser(session) {
2086
2208
  await this._refreshSession(session);
2209
+ session.suggestAccessTokenExpired();
2087
2210
  }
2088
2211
  async _refreshSession(session) {
2089
2212
  await this._currentUserCache.refresh([session]);