@stackframe/stack 2.6.34 → 2.6.36

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.
@@ -25,7 +25,7 @@ import { constructRedirectUrl } from "../utils/url";
25
25
  import { addNewOAuthProviderOrScope, callOAuthCallback, signInWithOAuth } from "./auth";
26
26
  import { createBrowserCookieHelper, createCookieHelper, deleteCookieClient, getCookieClient, setOrDeleteCookie, setOrDeleteCookieClient } from "./cookie";
27
27
  var NextNavigation = scrambleDuringCompileTime(NextNavigationUnscrambled);
28
- var clientVersion = "js @stackframe/stack@2.6.34";
28
+ var clientVersion = "js @stackframe/stack@2.6.36";
29
29
  function getUrls(partial) {
30
30
  const handler = partial.handler ?? "/handler";
31
31
  const home = partial.home ?? "/";
@@ -109,8 +109,9 @@ function useAsyncCache(cache, dependencies, caller) {
109
109
  const result = React.use(promise);
110
110
  if (result.status === "error") {
111
111
  const error = result.error;
112
- if (error instanceof Error) {
112
+ if (error instanceof Error && !error.__stackHasConcatenatedStacktraces) {
113
113
  concatStacktraces(error, new Error());
114
+ error.__stackHasConcatenatedStacktraces = true;
114
115
  }
115
116
  throw error;
116
117
  }
@@ -146,6 +147,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
146
147
  if (this.__DEMO_ENABLE_SLIGHT_FETCH_DELAY) {
147
148
  await wait(2e3);
148
149
  }
150
+ if (session.isKnownToBeInvalid()) {
151
+ return null;
152
+ }
149
153
  return await this._interface.getClientUserByToken(session);
150
154
  });
151
155
  this._currentProjectCache = createCache(async () => {
@@ -792,11 +796,14 @@ var _StackClientAppImpl = class __StackClientAppImpl {
792
796
  async update(update) {
793
797
  return await app._updateClientUser(update, session);
794
798
  },
795
- async sendVerificationEmail() {
799
+ async sendVerificationEmail(options) {
796
800
  if (!crud.primary_email) {
797
801
  throw new StackAssertionError("User does not have a primary email");
798
802
  }
799
- return await app._sendVerificationEmail(crud.primary_email, session);
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: ... })`");
805
+ }
806
+ return await app._interface.sendVerificationEmail(crud.primary_email, options?.callbackUrl ?? constructRedirectUrl(app.urls.emailVerification), session);
800
807
  },
801
808
  async updatePassword(options) {
802
809
  const result = await app._interface.updatePassword(options, session);
@@ -969,13 +976,17 @@ var _StackClientAppImpl = class __StackClientAppImpl {
969
976
  async redirectToTeamInvitation(options) {
970
977
  return await this._redirectToHandler("teamInvitation", options);
971
978
  }
972
- async sendForgotPasswordEmail(email) {
973
- const redirectUrl = constructRedirectUrl(this.urls.passwordReset);
974
- return await this._interface.sendForgotPasswordEmail(email, redirectUrl);
979
+ 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: ... })`");
982
+ }
983
+ return await this._interface.sendForgotPasswordEmail(email, options?.callbackUrl ?? constructRedirectUrl(this.urls.passwordReset));
975
984
  }
976
- async sendMagicLinkEmail(email) {
977
- const magicLinkRedirectUrl = constructRedirectUrl(this.urls.magicLinkCallback);
978
- return await this._interface.sendMagicLinkEmail(email, magicLinkRedirectUrl);
985
+ 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: ... })`");
988
+ }
989
+ return await this._interface.sendMagicLinkEmail(email, options?.callbackUrl ?? constructRedirectUrl(this.urls.magicLinkCallback));
979
990
  }
980
991
  async resetPassword(options) {
981
992
  return await this._interface.resetPassword(options);
@@ -1248,10 +1259,6 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1248
1259
  await this.redirectToAfterSignOut();
1249
1260
  }
1250
1261
  }
1251
- async _sendVerificationEmail(email, session) {
1252
- const emailVerificationRedirectUrl = constructRedirectUrl(this.urls.emailVerification);
1253
- return await this._interface.sendVerificationEmail(email, emailVerificationRedirectUrl, session);
1254
- }
1255
1262
  async signOut(options) {
1256
1263
  const user = await this.getUser();
1257
1264
  if (user) {
@@ -1331,7 +1338,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1331
1338
  return {
1332
1339
  toClientJson: () => {
1333
1340
  if (!("publishableClientKey" in this._interface.options)) {
1334
- throw Error("Cannot serialize to JSON from an application without a publishable client key");
1341
+ throw new StackAssertionError("Cannot serialize to JSON from an application without a publishable client key");
1335
1342
  }
1336
1343
  return {
1337
1344
  baseUrl: this._interface.options.baseUrl,
@@ -1375,6 +1382,9 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1375
1382
  });
1376
1383
  // TODO override the client user cache to use the server user cache, so we save some requests
1377
1384
  this._currentServerUserCache = createCacheBySession(async (session) => {
1385
+ if (session.isKnownToBeInvalid()) {
1386
+ return null;
1387
+ }
1378
1388
  return await this._interface.getServerUserByToken(session);
1379
1389
  });
1380
1390
  this._serverUsersCache = createCache(async ([cursor, limit, orderBy, desc, query]) => {
@@ -1469,8 +1479,11 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1469
1479
  isVerified: crud.is_verified,
1470
1480
  isPrimary: crud.is_primary,
1471
1481
  usedForAuth: crud.used_for_auth,
1472
- async sendVerificationEmail() {
1473
- await app._interface.sendServerContactChannelVerificationEmail(userId, crud.id, constructRedirectUrl(app.urls.emailVerification));
1482
+ async sendVerificationEmail(options) {
1483
+ if (!options?.callbackUrl && typeof window === "undefined") {
1484
+ throw new Error("Cannot send verification email without a callback URL from the server. Make sure you pass the `callbackUrl` option: `sendVerificationEmail({ callbackUrl: ... })`");
1485
+ }
1486
+ await app._interface.sendServerContactChannelVerificationEmail(userId, crud.id, options?.callbackUrl ?? constructRedirectUrl(app.urls.emailVerification));
1474
1487
  },
1475
1488
  async update(data) {
1476
1489
  await app._interface.updateServerContactChannel(userId, crud.id, serverContactChannelUpdateOptionsToCrud(data));