@stackframe/stack 2.7.12 → 2.7.16

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 (135) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/components/credential-sign-in.js.map +1 -1
  3. package/dist/components/credential-sign-up.js.map +1 -1
  4. package/dist/components/elements/form-warning.js.map +1 -1
  5. package/dist/components/elements/maybe-full-page.js.map +1 -1
  6. package/dist/components/elements/separator-with-text.js.map +1 -1
  7. package/dist/components/elements/sidebar-layout.js.map +1 -1
  8. package/dist/components/elements/ssr-layout-effect.js.map +1 -1
  9. package/dist/components/elements/user-avatar.js.map +1 -1
  10. package/dist/components/iframe-preventer.d.mts +8 -0
  11. package/dist/components/iframe-preventer.d.ts +8 -0
  12. package/dist/{utils/email.js → components/iframe-preventer.js} +28 -11
  13. package/dist/components/iframe-preventer.js.map +1 -0
  14. package/dist/components/magic-link-sign-in.js.map +1 -1
  15. package/dist/components/message-cards/known-error-message-card.js.map +1 -1
  16. package/dist/components/message-cards/message-card.js.map +1 -1
  17. package/dist/components/message-cards/predefined-message-card.js.map +1 -1
  18. package/dist/components/oauth-button-group.js.map +1 -1
  19. package/dist/components/oauth-button.js.map +1 -1
  20. package/dist/components/passkey-button.js.map +1 -1
  21. package/dist/components/profile-image-editor.js.map +1 -1
  22. package/dist/components/selected-team-switcher.js.map +1 -1
  23. package/dist/components/team-icon.js.map +1 -1
  24. package/dist/components/user-button.js.map +1 -1
  25. package/dist/components-page/account-settings.js +9 -1
  26. package/dist/components-page/account-settings.js.map +1 -1
  27. package/dist/components-page/auth-page.js.map +1 -1
  28. package/dist/components-page/email-verification.js.map +1 -1
  29. package/dist/components-page/error-page.js.map +1 -1
  30. package/dist/components-page/forgot-password.js.map +1 -1
  31. package/dist/components-page/magic-link-callback.js.map +1 -1
  32. package/dist/components-page/oauth-callback.js.map +1 -1
  33. package/dist/components-page/password-reset.js.map +1 -1
  34. package/dist/components-page/sign-in.js.map +1 -1
  35. package/dist/components-page/sign-out.js.map +1 -1
  36. package/dist/components-page/sign-up.js.map +1 -1
  37. package/dist/components-page/stack-handler.js +3 -2
  38. package/dist/components-page/stack-handler.js.map +1 -1
  39. package/dist/components-page/team-creation.js.map +1 -1
  40. package/dist/components-page/team-invitation.js.map +1 -1
  41. package/dist/esm/components/credential-sign-in.js.map +1 -1
  42. package/dist/esm/components/credential-sign-up.js.map +1 -1
  43. package/dist/esm/components/elements/form-warning.js.map +1 -1
  44. package/dist/esm/components/elements/maybe-full-page.js.map +1 -1
  45. package/dist/esm/components/elements/separator-with-text.js.map +1 -1
  46. package/dist/esm/components/elements/sidebar-layout.js.map +1 -1
  47. package/dist/esm/components/elements/ssr-layout-effect.js.map +1 -1
  48. package/dist/esm/components/elements/user-avatar.js.map +1 -1
  49. package/dist/esm/components/iframe-preventer.js +28 -0
  50. package/dist/esm/components/iframe-preventer.js.map +1 -0
  51. package/dist/esm/components/magic-link-sign-in.js.map +1 -1
  52. package/dist/esm/components/message-cards/known-error-message-card.js.map +1 -1
  53. package/dist/esm/components/message-cards/message-card.js.map +1 -1
  54. package/dist/esm/components/message-cards/predefined-message-card.js.map +1 -1
  55. package/dist/esm/components/oauth-button-group.js.map +1 -1
  56. package/dist/esm/components/oauth-button.js.map +1 -1
  57. package/dist/esm/components/passkey-button.js.map +1 -1
  58. package/dist/esm/components/profile-image-editor.js.map +1 -1
  59. package/dist/esm/components/selected-team-switcher.js.map +1 -1
  60. package/dist/esm/components/team-icon.js.map +1 -1
  61. package/dist/esm/components/user-button.js.map +1 -1
  62. package/dist/esm/components-page/account-settings.js +11 -3
  63. package/dist/esm/components-page/account-settings.js.map +1 -1
  64. package/dist/esm/components-page/auth-page.js.map +1 -1
  65. package/dist/esm/components-page/email-verification.js.map +1 -1
  66. package/dist/esm/components-page/error-page.js.map +1 -1
  67. package/dist/esm/components-page/forgot-password.js.map +1 -1
  68. package/dist/esm/components-page/magic-link-callback.js.map +1 -1
  69. package/dist/esm/components-page/oauth-callback.js.map +1 -1
  70. package/dist/esm/components-page/password-reset.js.map +1 -1
  71. package/dist/esm/components-page/sign-in.js.map +1 -1
  72. package/dist/esm/components-page/sign-out.js.map +1 -1
  73. package/dist/esm/components-page/sign-up.js.map +1 -1
  74. package/dist/esm/components-page/stack-handler.js +3 -2
  75. package/dist/esm/components-page/stack-handler.js.map +1 -1
  76. package/dist/esm/components-page/team-creation.js.map +1 -1
  77. package/dist/esm/components-page/team-invitation.js.map +1 -1
  78. package/dist/esm/generated/global-css.js +1 -1
  79. package/dist/esm/generated/global-css.js.map +1 -1
  80. package/dist/esm/generated/quetzal-translations.js.map +1 -1
  81. package/dist/esm/index.js +3 -5
  82. package/dist/esm/index.js.map +1 -1
  83. package/dist/esm/lib/auth.js.map +1 -1
  84. package/dist/esm/lib/cookie.js +15 -0
  85. package/dist/esm/lib/cookie.js.map +1 -1
  86. package/dist/esm/lib/hooks.js +2 -2
  87. package/dist/esm/lib/hooks.js.map +1 -1
  88. package/dist/esm/lib/stack-app.js +94 -56
  89. package/dist/esm/lib/stack-app.js.map +1 -1
  90. package/dist/esm/lib/translations.js.map +1 -1
  91. package/dist/esm/providers/stack-provider-client.js.map +1 -1
  92. package/dist/esm/providers/stack-provider.js.map +1 -1
  93. package/dist/esm/providers/theme-provider.js.map +1 -1
  94. package/dist/esm/providers/translation-provider-client.js.map +1 -1
  95. package/dist/esm/providers/translation-provider.js.map +1 -1
  96. package/dist/esm/utils/browser-script.js.map +1 -1
  97. package/dist/esm/utils/constants.js.map +1 -1
  98. package/dist/esm/utils/url.js +1 -1
  99. package/dist/esm/utils/url.js.map +1 -1
  100. package/dist/generated/global-css.d.mts +1 -1
  101. package/dist/generated/global-css.d.ts +1 -1
  102. package/dist/generated/global-css.js +1 -1
  103. package/dist/generated/global-css.js.map +1 -1
  104. package/dist/generated/quetzal-translations.js.map +1 -1
  105. package/dist/index.d.mts +8 -8
  106. package/dist/index.d.ts +8 -8
  107. package/dist/index.js +3 -3
  108. package/dist/index.js.map +1 -1
  109. package/dist/lib/auth.js.map +1 -1
  110. package/dist/lib/cookie.d.mts +2 -1
  111. package/dist/lib/cookie.d.ts +2 -1
  112. package/dist/lib/cookie.js +16 -0
  113. package/dist/lib/cookie.js.map +1 -1
  114. package/dist/lib/hooks.js +2 -2
  115. package/dist/lib/hooks.js.map +1 -1
  116. package/dist/lib/stack-app.d.mts +19 -9
  117. package/dist/lib/stack-app.d.ts +19 -9
  118. package/dist/lib/stack-app.js +92 -54
  119. package/dist/lib/stack-app.js.map +1 -1
  120. package/dist/lib/translations.js.map +1 -1
  121. package/dist/providers/stack-provider-client.js.map +1 -1
  122. package/dist/providers/stack-provider.js.map +1 -1
  123. package/dist/providers/theme-provider.js.map +1 -1
  124. package/dist/providers/translation-provider-client.js.map +1 -1
  125. package/dist/providers/translation-provider.js.map +1 -1
  126. package/dist/utils/browser-script.js.map +1 -1
  127. package/dist/utils/constants.js.map +1 -1
  128. package/dist/utils/url.js +1 -1
  129. package/dist/utils/url.js.map +1 -1
  130. package/package.json +10 -13
  131. package/dist/esm/utils/email.js +0 -10
  132. package/dist/esm/utils/email.js.map +0 -1
  133. package/dist/utils/email.d.mts +0 -3
  134. package/dist/utils/email.d.ts +0 -3
  135. package/dist/utils/email.js.map +0 -1
@@ -7,7 +7,7 @@ import { InternalSession } from "@stackframe/stack-shared/dist/sessions";
7
7
  import { encodeBase64 } from "@stackframe/stack-shared/dist/utils/bytes";
8
8
  import { AsyncCache } from "@stackframe/stack-shared/dist/utils/caches";
9
9
  import { scrambleDuringCompileTime } from "@stackframe/stack-shared/dist/utils/compile-time";
10
- import { isBrowserLike } from "@stackframe/stack-shared/dist/utils/env";
10
+ import { getPublicEnvVar, isBrowserLike } from "@stackframe/stack-shared/dist/utils/env";
11
11
  import { StackAssertionError, concatStacktraces, throwErr } from "@stackframe/stack-shared/dist/utils/errors";
12
12
  import { DependenciesMap } from "@stackframe/stack-shared/dist/utils/maps";
13
13
  import { deepPlainEquals, filterUndefined, omit, pick } from "@stackframe/stack-shared/dist/utils/objects";
@@ -23,9 +23,9 @@ import * as NextNavigationUnscrambled from "next/navigation";
23
23
  import React, { useCallback, useMemo } from "react";
24
24
  import { constructRedirectUrl } from "../utils/url";
25
25
  import { addNewOAuthProviderOrScope, callOAuthCallback, signInWithOAuth } from "./auth";
26
- import { createBrowserCookieHelper, createCookieHelper, deleteCookieClient, getCookieClient, setOrDeleteCookie, setOrDeleteCookieClient } from "./cookie";
26
+ import { createBrowserCookieHelper, createCookieHelper, createEmptyCookieHelper, deleteCookieClient, getCookieClient, setOrDeleteCookie, setOrDeleteCookieClient } from "./cookie";
27
27
  var NextNavigation = scrambleDuringCompileTime(NextNavigationUnscrambled);
28
- var clientVersion = "js @stackframe/stack@2.7.12";
28
+ var clientVersion = "js @stackframe/stack@2.7.16";
29
29
  function getUrls(partial) {
30
30
  const handler = partial.handler ?? "/handler";
31
31
  const home = partial.home ?? "/";
@@ -50,23 +50,11 @@ function getUrls(partial) {
50
50
  ...filterUndefined(partial)
51
51
  };
52
52
  }
53
- async function _redirectTo(url, options) {
54
- if (isReactServer) {
55
- NextNavigation.redirect(url.toString(), options?.replace ? NextNavigation.RedirectType.replace : NextNavigation.RedirectType.push);
56
- } else {
57
- if (options?.replace) {
58
- window.location.replace(url);
59
- } else {
60
- window.location.assign(url);
61
- }
62
- await wait(2e3);
63
- }
64
- }
65
53
  function getDefaultProjectId() {
66
- return process.env.NEXT_PUBLIC_STACK_PROJECT_ID || throwErr(new Error("Welcome to Stack Auth! It seems that you haven't provided a project ID. Please create a project on the Stack dashboard at https://app.stack-auth.com and put it in the NEXT_PUBLIC_STACK_PROJECT_ID environment variable."));
54
+ return getPublicEnvVar("NEXT_PUBLIC_STACK_PROJECT_ID") || throwErr(new Error("Welcome to Stack Auth! It seems that you haven't provided a project ID. Please create a project on the Stack dashboard at https://app.stack-auth.com and put it in the NEXT_PUBLIC_STACK_PROJECT_ID environment variable."));
67
55
  }
68
56
  function getDefaultPublishableClientKey() {
69
- return process.env.NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY || throwErr(new Error("Welcome to Stack Auth! It seems that you haven't provided a publishable client key. Please create an API key for your project on the Stack dashboard at https://app.stack-auth.com and copy your publishable client key into the NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY environment variable."));
57
+ return getPublicEnvVar("NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY") || throwErr(new Error("Welcome to Stack Auth! It seems that you haven't provided a publishable client key. Please create an API key for your project on the Stack dashboard at https://app.stack-auth.com and copy your publishable client key into the NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY environment variable."));
70
58
  }
71
59
  function getDefaultSecretServerKey() {
72
60
  return process.env.STACK_SECRET_SERVER_KEY || throwErr(new Error("No secret server key provided. Please copy your key from the Stack dashboard and put your it in the STACK_SECRET_SERVER_KEY environment variable."));
@@ -75,7 +63,8 @@ function getDefaultSuperSecretAdminKey() {
75
63
  return process.env.STACK_SUPER_SECRET_ADMIN_KEY || throwErr(new Error("No super secret admin key provided. Please copy your key from the Stack dashboard and put it in the STACK_SUPER_SECRET_ADMIN_KEY environment variable."));
76
64
  }
77
65
  function getDefaultBaseUrl() {
78
- return process.env.NEXT_PUBLIC_STACK_API_URL || process.env.NEXT_PUBLIC_STACK_URL || defaultBaseUrl;
66
+ const url = getPublicEnvVar("NEXT_PUBLIC_STACK_API_URL") || getPublicEnvVar("NEXT_PUBLIC_STACK_URL") || defaultBaseUrl;
67
+ return url.endsWith("/") ? url.slice(0, -1) : url;
79
68
  }
80
69
  var defaultBaseUrl = "https://api.stack-auth.com";
81
70
  function createEmptyTokenStore() {
@@ -226,13 +215,15 @@ var _StackClientAppImpl = class __StackClientAppImpl {
226
215
  this._interface = _options.interface;
227
216
  } else {
228
217
  this._interface = new StackClientInterface({
229
- baseUrl: _options.baseUrl ?? getDefaultBaseUrl(),
218
+ getBaseUrl: () => _options.baseUrl ?? getDefaultBaseUrl(),
230
219
  projectId: _options.projectId ?? getDefaultProjectId(),
231
220
  clientVersion,
232
221
  publishableClientKey: _options.publishableClientKey ?? getDefaultPublishableClientKey()
233
222
  });
234
223
  }
235
224
  this._tokenStoreInit = _options.tokenStore;
225
+ this._redirectMethod = _options.redirectMethod || "none";
226
+ this._redirectMethod = _options.redirectMethod || "nextjs";
236
227
  this._urlOptions = _options.urls ?? {};
237
228
  this._oauthScopesOnSignIn = _options.oauthScopesOnSignIn ?? {};
238
229
  if (_options.uniqueIdentifier) {
@@ -246,6 +237,13 @@ var _StackClientAppImpl = class __StackClientAppImpl {
246
237
  }
247
238
  }
248
239
  }
240
+ async _createCookieHelper() {
241
+ if (this._tokenStoreInit === "nextjs-cookie" || this._tokenStoreInit === "cookie") {
242
+ return await createCookieHelper();
243
+ } else {
244
+ return await createEmptyCookieHelper();
245
+ }
246
+ }
249
247
  async _getUserOAuthConnectionCacheFn(options) {
250
248
  const user = await options.getUser();
251
249
  let hasConnection = true;
@@ -483,7 +481,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
483
481
  return session;
484
482
  }
485
483
  async _getSession(overrideTokenStoreInit) {
486
- const tokenStore = this._getOrCreateTokenStore(await createCookieHelper(), overrideTokenStoreInit);
484
+ const tokenStore = this._getOrCreateTokenStore(await this._createCookieHelper(), overrideTokenStoreInit);
487
485
  return this._getSessionFromTokenStore(tokenStore);
488
486
  }
489
487
  _useSession(overrideTokenStoreInit) {
@@ -501,7 +499,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
501
499
  if (!("accessToken" in tokens) || !("refreshToken" in tokens)) {
502
500
  throw new StackAssertionError("Invalid tokens object; can't sign in with this", { tokens });
503
501
  }
504
- const tokenStore = this._getOrCreateTokenStore(await createCookieHelper());
502
+ const tokenStore = this._getOrCreateTokenStore(await this._createCookieHelper());
505
503
  tokenStore.set(tokens);
506
504
  }
507
505
  _hasPersistentTokenStore(overrideTokenStoreInit) {
@@ -571,8 +569,8 @@ var _StackClientAppImpl = class __StackClientAppImpl {
571
569
  clientMetadata: crud.client_metadata,
572
570
  clientReadOnlyMetadata: crud.client_read_only_metadata,
573
571
  async inviteUser(options) {
574
- if (!options.callbackUrl && typeof window === "undefined") {
575
- throw new Error("Cannot invite user without a callback URL from the server. Make sure you pass the `callbackUrl` option: `inviteUser({ email, callbackUrl: ... })`");
572
+ if (!options.callbackUrl && !await app._getCurrentUrl()) {
573
+ throw new Error("Cannot invite user without a callback URL from the server or without a redirect method. Make sure you pass the `callbackUrl` option: `inviteUser({ email, callbackUrl: ... })`");
576
574
  }
577
575
  await app._interface.sendTeamInvitation({
578
576
  teamId: crud.id,
@@ -652,7 +650,11 @@ var _StackClientAppImpl = class __StackClientAppImpl {
652
650
  const tokens = await this.currentSession.getTokens();
653
651
  return tokens;
654
652
  },
655
- async registerPasskey() {
653
+ async registerPasskey(options) {
654
+ const hostname = (await app._getCurrentUrl())?.hostname;
655
+ if (!hostname) {
656
+ throw new StackAssertionError("hostname must be provided if the Stack App does not have a redirect method");
657
+ }
656
658
  const initiationResult = await app._interface.initiatePasskeyRegistration({}, session);
657
659
  if (initiationResult.status !== "ok") {
658
660
  return Result.error(new KnownErrors.PasskeyRegistrationFailed("Failed to get initiation options for passkey registration"));
@@ -661,7 +663,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
661
663
  if (options_json.rp.id !== "THIS_VALUE_WILL_BE_REPLACED.example.com") {
662
664
  throw new StackAssertionError(`Expected returned RP ID from server to equal sentinel, but found ${options_json.rp.id}`);
663
665
  }
664
- options_json.rp.id = window.location.hostname;
666
+ options_json.rp.id = hostname;
665
667
  let attResp;
666
668
  try {
667
669
  attResp = await startRegistration({ optionsJSON: options_json });
@@ -762,10 +764,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
762
764
  return useMemo(() => teams.map((crud2) => app._clientTeamFromCrud(crud2, session)), [teams]);
763
765
  },
764
766
  async createTeam(data) {
765
- const crud2 = await app._interface.createClientTeam({
766
- ...teamCreateOptionsToCrud(data),
767
- creator_user_id: "me"
768
- }, session);
767
+ const crud2 = await app._interface.createClientTeam(teamCreateOptionsToCrud(data, "me"), session);
769
768
  await app._currentUserTeamsCache.refresh([session]);
770
769
  return app._clientTeamFromCrud(crud2, session);
771
770
  },
@@ -800,8 +799,8 @@ var _StackClientAppImpl = class __StackClientAppImpl {
800
799
  if (!crud.primary_email) {
801
800
  throw new StackAssertionError("User does not have a primary email");
802
801
  }
803
- if (!options?.callbackUrl && typeof window === "undefined") {
804
- throw new Error("Cannot send verification email without a callback URL from the server. Make sure you pass the `callbackUrl` option: `sendVerificationEmail({ callbackUrl: ... })`");
802
+ if (!options?.callbackUrl && !await app._getCurrentUrl()) {
803
+ throw new Error("Cannot send verification email without a callback URL from the server or without a redirect method. Make sure you pass the `callbackUrl` option: `sendVerificationEmail({ callbackUrl: ... })`");
805
804
  }
806
805
  return await app._interface.sendVerificationEmail(crud.primary_email, options?.callbackUrl ?? constructRedirectUrl(app.urls.emailVerification), session);
807
806
  },
@@ -871,7 +870,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
871
870
  _getOwnedAdminApp(forProjectId, session) {
872
871
  if (!this._ownedAdminApps.has([session, forProjectId])) {
873
872
  this._ownedAdminApps.set([session, forProjectId], new _StackAdminAppImpl({
874
- baseUrl: this._interface.options.baseUrl,
873
+ baseUrl: this._interface.options.getBaseUrl(),
875
874
  projectId: forProjectId,
876
875
  tokenStore: null,
877
876
  projectOwnerSession: session,
@@ -889,11 +888,32 @@ var _StackClientAppImpl = class __StackClientAppImpl {
889
888
  get urls() {
890
889
  return getUrls(this._urlOptions);
891
890
  }
891
+ async _getCurrentUrl() {
892
+ if (this._redirectMethod === "none") {
893
+ return null;
894
+ }
895
+ return new URL(window.location.href);
896
+ }
897
+ async _redirectTo(options) {
898
+ if (this._redirectMethod === "none") {
899
+ return;
900
+ }
901
+ if (isReactServer && this._redirectMethod === "nextjs") {
902
+ NextNavigation.redirect(options.url.toString(), options.replace ? NextNavigation.RedirectType.replace : NextNavigation.RedirectType.push);
903
+ } else {
904
+ if (options.replace) {
905
+ window.location.replace(options.url);
906
+ } else {
907
+ window.location.assign(options.url);
908
+ }
909
+ await wait(2e3);
910
+ }
911
+ }
892
912
  async _redirectIfTrusted(url, options) {
893
913
  if (!await this._isTrusted(url)) {
894
914
  throw new Error(`Redirect URL ${url} is not trusted; should be relative.`);
895
915
  }
896
- return await _redirectTo(url, options);
916
+ return await this._redirectTo({ url, ...options });
897
917
  }
898
918
  async _redirectToHandler(handlerName, options) {
899
919
  let url = this.urls[handlerName];
@@ -977,14 +997,14 @@ var _StackClientAppImpl = class __StackClientAppImpl {
977
997
  return await this._redirectToHandler("teamInvitation", options);
978
998
  }
979
999
  async sendForgotPasswordEmail(email, options) {
980
- if (!options?.callbackUrl && typeof window === "undefined") {
981
- throw new Error("Cannot send forgot password email without a callback URL from the server. Make sure you pass the `callbackUrl` option: `sendForgotPasswordEmail({ email, callbackUrl: ... })`");
1000
+ if (!options?.callbackUrl && !await this._getCurrentUrl()) {
1001
+ throw new Error("Cannot send forgot password email without a callback URL from the server or without a redirect method. Make sure you pass the `callbackUrl` option: `sendForgotPasswordEmail({ email, callbackUrl: ... })`");
982
1002
  }
983
1003
  return await this._interface.sendForgotPasswordEmail(email, options?.callbackUrl ?? constructRedirectUrl(this.urls.passwordReset));
984
1004
  }
985
1005
  async sendMagicLinkEmail(email, options) {
986
- if (!options?.callbackUrl && typeof window === "undefined") {
987
- throw new Error("Cannot send magic link email without a callback URL from the server. Make sure you pass the `callbackUrl` option: `sendMagicLinkEmail({ email, callbackUrl: ... })`");
1006
+ if (!options?.callbackUrl && !await this._getCurrentUrl()) {
1007
+ throw new Error("Cannot send magic link email without a callback URL from the server or without a redirect method. Make sure you pass the `callbackUrl` option: `sendMagicLinkEmail({ email, callbackUrl: ... })`");
988
1008
  }
989
1009
  return await this._interface.sendMagicLinkEmail(email, options?.callbackUrl ?? constructRedirectUrl(this.urls.magicLinkCallback));
990
1010
  }
@@ -1081,6 +1101,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1081
1101
  return res;
1082
1102
  }
1083
1103
  async signInWithOAuth(provider) {
1104
+ if (typeof window === "undefined") {
1105
+ throw new Error("signInWithOAuth can currently only be called in a browser environment");
1106
+ }
1084
1107
  this._ensurePersistentTokenStore();
1085
1108
  await signInWithOAuth(
1086
1109
  this._interface,
@@ -1224,6 +1247,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1224
1247
  }
1225
1248
  }
1226
1249
  async callOAuthCallback() {
1250
+ if (typeof window === "undefined") {
1251
+ throw new Error("callOAuthCallback can currently only be called in a browser environment");
1252
+ }
1227
1253
  this._ensurePersistentTokenStore();
1228
1254
  let result;
1229
1255
  try {
@@ -1233,13 +1259,15 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1233
1259
  } catch (e) {
1234
1260
  if (e instanceof KnownErrors.InvalidTotpCode) {
1235
1261
  alert("Invalid TOTP code. Please try signing in again.");
1262
+ return false;
1263
+ } else {
1264
+ throw e;
1236
1265
  }
1237
- throw e;
1238
1266
  }
1239
1267
  if (result.status === "ok" && result.data) {
1240
1268
  await this._signInToAccountWithTokens(result.data);
1241
1269
  if ("afterCallbackRedirectUrl" in result.data && result.data.afterCallbackRedirectUrl) {
1242
- await _redirectTo(result.data.afterCallbackRedirectUrl, { replace: true });
1270
+ await this._redirectTo({ url: result.data.afterCallbackRedirectUrl, replace: true });
1243
1271
  return true;
1244
1272
  } else if (result.data.newUser) {
1245
1273
  await this.redirectToAfterSignUp({ replace: true });
@@ -1255,7 +1283,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1255
1283
  await storeLock.withWriteLock(async () => {
1256
1284
  await this._interface.signOut(session);
1257
1285
  if (options?.redirectUrl) {
1258
- await _redirectTo(options.redirectUrl);
1286
+ await this._redirectTo({ url: options.redirectUrl, replace: true });
1259
1287
  } else {
1260
1288
  await this.redirectToAfterSignOut();
1261
1289
  }
@@ -1343,7 +1371,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1343
1371
  throw new StackAssertionError("Cannot serialize to JSON from an application without a publishable client key");
1344
1372
  }
1345
1373
  return {
1346
- baseUrl: this._interface.options.baseUrl,
1374
+ baseUrl: this._options.baseUrl,
1347
1375
  projectId: this.projectId,
1348
1376
  publishableClientKey: this._interface.options.publishableClientKey,
1349
1377
  tokenStore: this._tokenStoreInit,
@@ -1372,7 +1400,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1372
1400
  oauthScopesOnSignIn: options.oauthScopesOnSignIn
1373
1401
  } : {
1374
1402
  interface: new StackServerInterface({
1375
- baseUrl: options.baseUrl ?? getDefaultBaseUrl(),
1403
+ getBaseUrl: () => options.baseUrl ?? getDefaultBaseUrl(),
1376
1404
  projectId: options.projectId ?? getDefaultProjectId(),
1377
1405
  clientVersion,
1378
1406
  publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
@@ -1482,8 +1510,8 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1482
1510
  isPrimary: crud.is_primary,
1483
1511
  usedForAuth: crud.used_for_auth,
1484
1512
  async sendVerificationEmail(options) {
1485
- if (!options?.callbackUrl && typeof window === "undefined") {
1486
- throw new Error("Cannot send verification email without a callback URL from the server. Make sure you pass the `callbackUrl` option: `sendVerificationEmail({ callbackUrl: ... })`");
1513
+ if (!options?.callbackUrl && !await app._getCurrentUrl()) {
1514
+ throw new Error("Cannot send verification email without a callback URL from the server or without a redirect method. Make sure you pass the `callbackUrl` option: `sendVerificationEmail({ callbackUrl: ... })`");
1487
1515
  }
1488
1516
  await app._interface.sendServerContactChannelVerificationEmail(userId, crud.id, options?.callbackUrl ?? constructRedirectUrl(app.urls.emailVerification));
1489
1517
  },
@@ -1574,10 +1602,10 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1574
1602
  return useMemo(() => teams.map((t) => app._serverTeamFromCrud(t)), [teams]);
1575
1603
  },
1576
1604
  createTeam: async (data) => {
1577
- const team = await app._interface.createServerTeam({
1578
- ...serverTeamCreateOptionsToCrud(data),
1579
- creator_user_id: crud.id
1580
- });
1605
+ const team = await app._interface.createServerTeam(serverTeamCreateOptionsToCrud({
1606
+ creatorUserId: crud.id,
1607
+ ...data
1608
+ }));
1581
1609
  await app._serverTeamsCache.refresh([void 0]);
1582
1610
  return app._serverTeamFromCrud(team);
1583
1611
  },
@@ -1714,8 +1742,8 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1714
1742
  await app._serverTeamMemberProfilesCache.refresh([crud.id]);
1715
1743
  },
1716
1744
  async inviteUser(options) {
1717
- if (!options.callbackUrl && typeof window === "undefined") {
1718
- throw new Error("Cannot invite user without a callback URL from the server. Make sure you pass the `callbackUrl` option: `inviteUser({ email, callbackUrl: ... })`");
1745
+ if (!options.callbackUrl && !await app._getCurrentUrl()) {
1746
+ throw new Error("Cannot invite user without a callback URL from the server or without a redirect method. Make sure you pass the `callbackUrl` option: `inviteUser({ email, callbackUrl: ... })`");
1719
1747
  }
1720
1748
  await app._interface.sendServerTeamInvitation({
1721
1749
  teamId: crud.id,
@@ -1863,7 +1891,9 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1863
1891
  async _refreshUsers() {
1864
1892
  await Promise.all([
1865
1893
  super._refreshUsers(),
1866
- this._serverUsersCache.refreshWhere(() => true)
1894
+ this._serverUserCache.refreshWhere(() => true),
1895
+ this._serverUsersCache.refreshWhere(() => true),
1896
+ this._serverContactChannelsCache.refreshWhere(() => true)
1867
1897
  ]);
1868
1898
  }
1869
1899
  };
@@ -1871,7 +1901,7 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
1871
1901
  constructor(options) {
1872
1902
  super({
1873
1903
  interface: new StackAdminInterface({
1874
- baseUrl: options.baseUrl ?? getDefaultBaseUrl(),
1904
+ getBaseUrl: () => options.baseUrl ?? getDefaultBaseUrl(),
1875
1905
  projectId: options.projectId ?? getDefaultProjectId(),
1876
1906
  clientVersion,
1877
1907
  ..."projectOwnerSession" in options ? {
@@ -2201,7 +2231,10 @@ function serverUserCreateOptionsToCrud(options) {
2201
2231
  otp_auth_enabled: options.otpAuthEnabled,
2202
2232
  primary_email_auth_enabled: options.primaryEmailAuthEnabled,
2203
2233
  display_name: options.displayName,
2204
- primary_email_verified: options.primaryEmailVerified
2234
+ primary_email_verified: options.primaryEmailVerified,
2235
+ client_metadata: options.clientMetadata,
2236
+ client_read_only_metadata: options.clientReadOnlyMetadata,
2237
+ server_metadata: options.serverMetadata
2205
2238
  };
2206
2239
  }
2207
2240
  function adminProjectUpdateOptionsToCrud(options) {
@@ -2272,14 +2305,19 @@ function teamUpdateOptionsToCrud(options) {
2272
2305
  client_metadata: options.clientMetadata
2273
2306
  };
2274
2307
  }
2275
- function teamCreateOptionsToCrud(options) {
2308
+ function teamCreateOptionsToCrud(options, creatorUserId) {
2276
2309
  return {
2277
2310
  display_name: options.displayName,
2278
- profile_image_url: options.profileImageUrl
2311
+ profile_image_url: options.profileImageUrl,
2312
+ creator_user_id: creatorUserId
2279
2313
  };
2280
2314
  }
2281
2315
  function serverTeamCreateOptionsToCrud(options) {
2282
- return teamCreateOptionsToCrud(options);
2316
+ return {
2317
+ display_name: options.displayName,
2318
+ profile_image_url: options.profileImageUrl,
2319
+ creator_user_id: options.creatorUserId
2320
+ };
2283
2321
  }
2284
2322
  function serverTeamUpdateOptionsToCrud(options) {
2285
2323
  return {