@stackframe/stack 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 +56 -20
  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 +56 -20
  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 +6 -5
  74. package/CHANGELOG.md +0 -2052
@@ -40,6 +40,7 @@ var import_bytes = require("@stackframe/stack-shared/dist/utils/bytes");
40
40
  var import_compile_time = require("@stackframe/stack-shared/dist/utils/compile-time");
41
41
  var import_env = require("@stackframe/stack-shared/dist/utils/env");
42
42
  var import_errors = require("@stackframe/stack-shared/dist/utils/errors");
43
+ var import_json = require("@stackframe/stack-shared/dist/utils/json");
43
44
  var import_maps = require("@stackframe/stack-shared/dist/utils/maps");
44
45
  var import_objects = require("@stackframe/stack-shared/dist/utils/objects");
45
46
  var import_promises = require("@stackframe/stack-shared/dist/utils/promises");
@@ -62,7 +63,6 @@ var import_projects = require("../../projects/index.js");
62
63
  var import_teams = require("../../teams/index.js");
63
64
  var import_users = require("../../users/index.js");
64
65
  var import_common2 = require("./common.js");
65
- var import_json = require("@stackframe/stack-shared/dist/utils/json");
66
66
  var import_common3 = require("./common.js");
67
67
  var sc = __toESM(require("@stackframe/stack-sc"));
68
68
  var import_stack_sc = require("@stackframe/stack-sc");
@@ -503,9 +503,10 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
503
503
  return;
504
504
  }
505
505
  const domain = await this._trustedParentDomainCache.getOrWait([hostname], "read-write");
506
+ const cookieOptions = { maxAge: 60 * 60 * 24 * 365, noOpIfServerComponent: true };
506
507
  const setCookie = async (targetDomain, value2) => {
507
508
  const name = this._getCustomRefreshCookieName(targetDomain);
508
- const options = { maxAge: 60 * 60 * 24 * 365, domain: targetDomain, noOpIfServerComponent: true };
509
+ const options = { ...cookieOptions, domain: targetDomain };
509
510
  if (context === "browser") {
510
511
  (0, import_cookie.setOrDeleteCookieClient)(name, value2, options);
511
512
  } else {
@@ -518,7 +519,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
518
519
  const value = refreshToken && updatedAt ? this._formatRefreshCookieValue(refreshToken, updatedAt) : null;
519
520
  await setCookie(domain.data, value);
520
521
  const isSecure = await (0, import_cookie.isSecure)();
521
- await (0, import_cookie.setOrDeleteCookie)(this._getRefreshTokenDefaultCookieNameForSecure(isSecure), null);
522
+ await (0, import_cookie.setOrDeleteCookie)(this._getRefreshTokenDefaultCookieNameForSecure(isSecure), null, cookieOptions);
522
523
  });
523
524
  }
524
525
  async _getTrustedParentDomain(currentDomain) {
@@ -570,7 +571,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
570
571
  );
571
572
  (0, import_cookie.setOrDeleteCookieClient)(defaultName, refreshCookieValue, { maxAge: 60 * 60 * 24 * 365, secure });
572
573
  (0, import_cookie.setOrDeleteCookieClient)(this._accessTokenCookieName, accessTokenPayload, { maxAge: 60 * 60 * 24 });
573
- cookieNamesToDelete.forEach((name) => (0, import_cookie.deleteCookieClient)(name));
574
+ cookieNamesToDelete.forEach((name) => (0, import_cookie.deleteCookieClient)(name, {}));
574
575
  this._queueCustomRefreshCookieUpdate(refreshToken, updatedAt, "browser");
575
576
  hasSucceededInWriting = true;
576
577
  } catch (e) {
@@ -614,7 +615,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
614
615
  if (cookieNamesToDelete.length > 0) {
615
616
  await Promise.all(
616
617
  cookieNamesToDelete.map(
617
- (name) => (0, import_cookie.setOrDeleteCookie)(name, null, { noOpIfServerComponent: true })
618
+ (name) => (0, import_cookie.deleteCookie)(name, { noOpIfServerComponent: true })
618
619
  )
619
620
  );
620
621
  }
@@ -979,22 +980,65 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
979
980
  _internalSession: session,
980
981
  currentSession: {
981
982
  async getTokens() {
982
- const tokens = await session.getOrFetchLikelyValidTokens(2e4);
983
+ const tokens = await session.getOrFetchLikelyValidTokens(2e4, 75e3);
983
984
  return {
984
985
  accessToken: tokens?.accessToken.token ?? null,
985
986
  refreshToken: tokens?.refreshToken?.token ?? null
986
987
  };
988
+ },
989
+ useTokens() {
990
+ const [_, setCounter] = import_react2.default.useState(0);
991
+ import_react2.default.useEffect(() => {
992
+ const { unsubscribe: unsubscribeRefresh } = session.startRefreshingAccessToken(3e4, 6e4);
993
+ const { unsubscribe: unsubscribeInvalidate } = session.onInvalidate(() => setCounter((c) => c + 1));
994
+ const { unsubscribe: unsubscribeAccessTokenChange } = session.onAccessTokenChange(() => setCounter((c) => c + 1));
995
+ return () => {
996
+ unsubscribeRefresh();
997
+ unsubscribeInvalidate();
998
+ unsubscribeAccessTokenChange();
999
+ };
1000
+ }, []);
1001
+ let accessToken = session.isKnownToBeInvalid() ? null : session.getAccessTokenIfNotExpiredYet(2e4, 75e3);
1002
+ if (accessToken === null) {
1003
+ accessToken = (0, import_react.use)(session.getOrFetchLikelyValidTokens(2e4, 75e3))?.accessToken ?? null;
1004
+ }
1005
+ return {
1006
+ accessToken: accessToken?.token ?? null,
1007
+ refreshToken: session.getRefreshToken()?.token ?? null
1008
+ };
987
1009
  }
988
1010
  },
1011
+ async getAccessToken() {
1012
+ const tokens = await this.currentSession.getTokens();
1013
+ return tokens.accessToken;
1014
+ },
1015
+ useAccessToken() {
1016
+ return this.currentSession.useTokens().accessToken;
1017
+ },
1018
+ async getRefreshToken() {
1019
+ const tokens = await this.currentSession.getTokens();
1020
+ return tokens.refreshToken;
1021
+ },
1022
+ useRefreshToken() {
1023
+ return this.currentSession.useTokens().refreshToken;
1024
+ },
989
1025
  async getAuthHeaders() {
990
1026
  return {
991
1027
  "x-stack-auth": JSON.stringify(await this.getAuthJson())
992
1028
  };
993
1029
  },
1030
+ useAuthHeaders() {
1031
+ return {
1032
+ "x-stack-auth": JSON.stringify(this.useAuthJson())
1033
+ };
1034
+ },
994
1035
  async getAuthJson() {
995
1036
  const tokens = await this.currentSession.getTokens();
996
1037
  return tokens;
997
1038
  },
1039
+ useAuthJson() {
1040
+ return this.currentSession.useTokens();
1041
+ },
998
1042
  signOut(options) {
999
1043
  return app._signOut(session, options);
1000
1044
  }
@@ -1035,6 +1079,8 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1035
1079
  passkeyAuthEnabled: crud.passkey_auth_enabled,
1036
1080
  isMultiFactorRequired: crud.requires_totp_mfa,
1037
1081
  isAnonymous: crud.is_anonymous,
1082
+ isRestricted: crud.is_restricted,
1083
+ restrictedReason: crud.restricted_reason,
1038
1084
  toClientJson() {
1039
1085
  return crud;
1040
1086
  }
@@ -1065,7 +1111,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1065
1111
  return this.update({ clientMetadata: metadata });
1066
1112
  },
1067
1113
  async setSelectedTeam(team) {
1068
- await this.update({ selectedTeamId: team?.id ?? null });
1114
+ await this.update({ selectedTeamId: typeof team === "string" ? team : team?.id ?? null });
1069
1115
  },
1070
1116
  getConnectedAccount,
1071
1117
  useConnectedAccount,
@@ -1345,6 +1391,25 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1345
1391
  const response = import_results.Result.orThrow(await this._customProductsCache.getOrWait([session, options.customCustomerId, options.cursor ?? null, options.limit ?? null], "write-only"));
1346
1392
  return this._customerProductsFromResponse(response);
1347
1393
  }
1394
+ async cancelSubscription(options) {
1395
+ const session = await this._getSession();
1396
+ const user = await this.getUser();
1397
+ if (!user) {
1398
+ throw new import_stack_shared.KnownErrors.UserAuthenticationRequired();
1399
+ }
1400
+ const customerType = "teamId" in options ? "team" : "user";
1401
+ const customerId = "teamId" in options ? options.teamId : user.id;
1402
+ await this._interface.cancelSubscription({
1403
+ customer_type: customerType,
1404
+ customer_id: customerId,
1405
+ product_id: options.productId
1406
+ }, session);
1407
+ if (customerType === "user") {
1408
+ await this._userProductsCache.invalidateWhere(([cachedSession, userId]) => cachedSession === session && userId === customerId);
1409
+ } else {
1410
+ await this._teamProductsCache.invalidateWhere(([cachedSession, teamId]) => cachedSession === session && teamId === customerId);
1411
+ }
1412
+ }
1348
1413
  useProducts(options) {
1349
1414
  const session = this._useSession();
1350
1415
  const cache = "userId" in options ? this._userProductsCache : "teamId" in options ? this._teamProductsCache : this._customProductsCache;
@@ -1354,15 +1419,13 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1354
1419
  return this._customerProductsFromResponse(response);
1355
1420
  }
1356
1421
  _currentUserFromCrud(crud, session) {
1357
- const currentUser = {
1422
+ const currentUser = (0, import_users.withUserDestructureGuard)({
1358
1423
  ...this._createBaseUser(crud),
1359
1424
  ...this._createAuth(session),
1360
1425
  ...this._createUserExtraFromCurrent(crud, session),
1361
1426
  ...this._isInternalProject() ? this._createInternalUserExtra(session) : {},
1362
1427
  ...this._createCustomer(crud.id, "user", session)
1363
- };
1364
- (0, import_users.attachUserDestructureGuard)(currentUser);
1365
- Object.freeze(currentUser);
1428
+ });
1366
1429
  return currentUser;
1367
1430
  }
1368
1431
  _clientSessionFromCrud(crud) {
@@ -1450,7 +1513,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1450
1513
  const queryParams = new URLSearchParams(window.location.search);
1451
1514
  url = queryParams.get("after_auth_return_to") || url;
1452
1515
  }
1453
- } else if (handlerName === "signIn" || handlerName === "signUp") {
1516
+ } else if (handlerName === "signIn" || handlerName === "signUp" || handlerName === "onboarding") {
1454
1517
  if (isReactServer2 || typeof window === "undefined") {
1455
1518
  } else {
1456
1519
  const currentUrl = new URL(window.location.href);
@@ -1499,6 +1562,9 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1499
1562
  async redirectToAfterSignUp(options) {
1500
1563
  return await this._redirectToHandler("afterSignUp", options);
1501
1564
  }
1565
+ async redirectToOnboarding(options) {
1566
+ return await this._redirectToHandler("onboarding", options);
1567
+ }
1502
1568
  async redirectToAfterSignOut(options) {
1503
1569
  return await this._redirectToHandler("afterSignOut", options);
1504
1570
  }
@@ -1564,16 +1630,22 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1564
1630
  return result;
1565
1631
  }
1566
1632
  async getUser(options) {
1633
+ if (options?.or === "anonymous" && options.includeRestricted === false) {
1634
+ throw new Error("Cannot use { or: 'anonymous' } with { includeRestricted: false }. Anonymous users implicitly include restricted users.");
1635
+ }
1567
1636
  this._ensurePersistentTokenStore(options?.tokenStore);
1568
1637
  const session = await this._getSession(options?.tokenStore);
1569
1638
  let crud = import_results.Result.orThrow(await this._currentUserCache.getOrWait([session], "write-only"));
1570
- if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists[deprecated]") {
1571
- crud = null;
1572
- }
1573
- if (crud === null) {
1639
+ const includeAnonymous = options?.or === "anonymous" || options?.or === "anonymous-if-exists[deprecated]";
1640
+ const includeRestricted = options?.includeRestricted === true || includeAnonymous;
1641
+ if (crud === null || crud.is_anonymous && !includeAnonymous || crud.is_restricted && !includeRestricted) {
1574
1642
  switch (options?.or) {
1575
1643
  case "redirect": {
1576
- await this.redirectToSignIn({ replace: true });
1644
+ if (!crud?.is_anonymous && crud?.is_restricted) {
1645
+ await this.redirectToOnboarding({ replace: true });
1646
+ } else {
1647
+ await this.redirectToSignIn({ replace: true });
1648
+ }
1577
1649
  break;
1578
1650
  }
1579
1651
  case "throw": {
@@ -1581,7 +1653,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1581
1653
  }
1582
1654
  case "anonymous": {
1583
1655
  const tokens = await this._signUpAnonymously();
1584
- return await this.getUser({ tokenStore: tokens, or: "anonymous-if-exists[deprecated]" }) ?? (0, import_errors.throwErr)("Something went wrong while signing up anonymously");
1656
+ return await this.getUser({ tokenStore: tokens, or: "anonymous-if-exists[deprecated]", includeRestricted: true }) ?? (0, import_errors.throwErr)("Something went wrong while signing up anonymously");
1585
1657
  }
1586
1658
  case void 0:
1587
1659
  case "anonymous-if-exists[deprecated]":
@@ -1593,16 +1665,22 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1593
1665
  return crud && this._currentUserFromCrud(crud, session);
1594
1666
  }
1595
1667
  useUser(options) {
1668
+ if (options?.or === "anonymous" && options.includeRestricted === false) {
1669
+ throw new Error("Cannot use { or: 'anonymous' } with { includeRestricted: false }. Anonymous users implicitly include restricted users.");
1670
+ }
1596
1671
  this._ensurePersistentTokenStore(options?.tokenStore);
1597
1672
  const session = this._useSession(options?.tokenStore);
1598
1673
  let crud = (0, import_common3.useAsyncCache)(this._currentUserCache, [session], "clientApp.useUser()");
1599
- if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists[deprecated]") {
1600
- crud = null;
1601
- }
1602
- if (crud === null) {
1674
+ const includeAnonymous = options?.or === "anonymous" || options?.or === "anonymous-if-exists[deprecated]";
1675
+ const includeRestricted = options?.includeRestricted === true || includeAnonymous;
1676
+ if (crud === null || crud.is_anonymous && !includeAnonymous || crud.is_restricted && !includeRestricted) {
1603
1677
  switch (options?.or) {
1604
1678
  case "redirect": {
1605
- (0, import_promises.runAsynchronously)(this.redirectToSignIn({ replace: true }));
1679
+ if (!crud?.is_anonymous && crud?.is_restricted) {
1680
+ (0, import_promises.runAsynchronously)(this.redirectToOnboarding({ replace: true }));
1681
+ } else {
1682
+ (0, import_promises.runAsynchronously)(this.redirectToSignIn({ replace: true }));
1683
+ }
1606
1684
  (0, import_react.suspend)();
1607
1685
  throw new import_errors.StackAssertionError("suspend should never return");
1608
1686
  }
@@ -1630,7 +1708,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1630
1708
  }, [crud, session, options?.or]);
1631
1709
  }
1632
1710
  _getTokenPartialUserFromSession(session, options) {
1633
- const accessToken = session.getAccessTokenIfNotExpiredYet(0);
1711
+ const accessToken = session.getAccessTokenIfNotExpiredYet(0, null);
1634
1712
  if (!accessToken) {
1635
1713
  return null;
1636
1714
  }
@@ -1643,7 +1721,9 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1643
1721
  primaryEmail: accessToken.payload.email,
1644
1722
  displayName: accessToken.payload.name,
1645
1723
  primaryEmailVerified: accessToken.payload.email_verified,
1646
- isAnonymous
1724
+ isAnonymous,
1725
+ isRestricted: accessToken.payload.is_restricted,
1726
+ restrictedReason: accessToken.payload.restricted_reason
1647
1727
  };
1648
1728
  }
1649
1729
  async _getPartialUserFromConvex(ctx) {
@@ -1656,7 +1736,9 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1656
1736
  displayName: auth.name ?? null,
1657
1737
  primaryEmail: auth.email ?? null,
1658
1738
  primaryEmailVerified: auth.email_verified,
1659
- isAnonymous: auth.is_anonymous
1739
+ isAnonymous: auth.is_anonymous,
1740
+ isRestricted: auth.is_restricted,
1741
+ restrictedReason: auth.restricted_reason ?? null
1660
1742
  };
1661
1743
  }
1662
1744
  async getPartialUser(options) {
@@ -1694,7 +1776,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1694
1776
  return async (args) => {
1695
1777
  const session = await this._getSession(options.tokenStore ?? this._tokenStoreInit);
1696
1778
  if (!args.forceRefreshToken) {
1697
- const tokens2 = await session.getOrFetchLikelyValidTokens(2e4);
1779
+ const tokens2 = await session.getOrFetchLikelyValidTokens(2e4, 75e3);
1698
1780
  return tokens2?.accessToken.token ?? null;
1699
1781
  }
1700
1782
  const tokens = await session.fetchNewTokens();
@@ -1703,7 +1785,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1703
1785
  }
1704
1786
  async getConvexHttpClientAuth(options) {
1705
1787
  const session = await this._getSession(options.tokenStore);
1706
- const tokens = await session.getOrFetchLikelyValidTokens(2e4);
1788
+ const tokens = await session.getOrFetchLikelyValidTokens(2e4, 75e3);
1707
1789
  return tokens?.accessToken.token ?? "";
1708
1790
  }
1709
1791
  async _updateClientUser(update, session) {
@@ -2050,11 +2132,44 @@ ${url}`);
2050
2132
  await user.signOut({ redirectUrl: options?.redirectUrl });
2051
2133
  }
2052
2134
  }
2135
+ async getAccessToken(options) {
2136
+ const user = await this.getUser({ tokenStore: options?.tokenStore ?? void 0 });
2137
+ if (user) {
2138
+ return await user.getAccessToken();
2139
+ }
2140
+ return null;
2141
+ }
2142
+ useAccessToken(options) {
2143
+ const user = this.useUser({ tokenStore: options?.tokenStore ?? void 0 });
2144
+ if (user) {
2145
+ return user.useAccessToken();
2146
+ }
2147
+ return null;
2148
+ }
2149
+ async getRefreshToken(options) {
2150
+ const user = await this.getUser({ tokenStore: options?.tokenStore ?? void 0 });
2151
+ if (user) {
2152
+ return await user.getRefreshToken();
2153
+ }
2154
+ return null;
2155
+ }
2156
+ useRefreshToken(options) {
2157
+ const user = this.useUser({ tokenStore: options?.tokenStore ?? void 0 });
2158
+ if (user) {
2159
+ return user.useRefreshToken();
2160
+ }
2161
+ return null;
2162
+ }
2053
2163
  async getAuthHeaders(options) {
2054
2164
  return {
2055
2165
  "x-stack-auth": JSON.stringify(await this.getAuthJson(options))
2056
2166
  };
2057
2167
  }
2168
+ useAuthHeaders(options) {
2169
+ return {
2170
+ "x-stack-auth": JSON.stringify(this.useAuthJson(options))
2171
+ };
2172
+ }
2058
2173
  async getAuthJson(options) {
2059
2174
  const user = await this.getUser({ tokenStore: options?.tokenStore ?? void 0 });
2060
2175
  if (user) {
@@ -2062,6 +2177,13 @@ ${url}`);
2062
2177
  }
2063
2178
  return { accessToken: null, refreshToken: null };
2064
2179
  }
2180
+ useAuthJson(options) {
2181
+ const user = this.useUser({ tokenStore: options?.tokenStore ?? void 0 });
2182
+ if (user) {
2183
+ return user.useAuthJson();
2184
+ }
2185
+ return { accessToken: null, refreshToken: null };
2186
+ }
2065
2187
  async getProject() {
2066
2188
  const crud = import_results.Result.orThrow(await this._currentProjectCache.getOrWait([], "write-only"));
2067
2189
  return this._clientProjectFromCrud(crud);
@@ -2098,6 +2220,7 @@ ${url}`);
2098
2220
  }
2099
2221
  async _refreshUser(session) {
2100
2222
  await this._refreshSession(session);
2223
+ session.suggestAccessTokenExpired();
2101
2224
  }
2102
2225
  async _refreshSession(session) {
2103
2226
  await this._currentUserCache.refresh([session]);