@stackframe/stack 2.7.16 → 2.7.18

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.
@@ -22,7 +22,7 @@ declare function callOAuthCallback(iface: StackClientInterface, redirectUrl: str
22
22
  status: "ok";
23
23
  data: {
24
24
  newUser: boolean;
25
- afterCallbackRedirectUrl?: string | undefined;
25
+ afterCallbackRedirectUrl?: string;
26
26
  accessToken: string;
27
27
  refreshToken: string;
28
28
  };
@@ -22,7 +22,7 @@ declare function callOAuthCallback(iface: StackClientInterface, redirectUrl: str
22
22
  status: "ok";
23
23
  data: {
24
24
  newUser: boolean;
25
- afterCallbackRedirectUrl?: string | undefined;
25
+ afterCallbackRedirectUrl?: string;
26
26
  accessToken: string;
27
27
  refreshToken: string;
28
28
  };
@@ -43,7 +43,10 @@ type OAuthScopesOnSignIn = {
43
43
  type ProjectCurrentUser<ProjectId> = ProjectId extends "internal" ? CurrentInternalUser : CurrentUser;
44
44
  type ProjectCurrentServerUser<ProjectId> = ProjectId extends "internal" ? CurrentInternalServerUser : CurrentServerUser;
45
45
  type StackClientAppConstructorOptions<HasTokenStore extends boolean, ProjectId extends string> = {
46
- baseUrl?: string;
46
+ baseUrl?: string | {
47
+ browser: string;
48
+ server: string;
49
+ };
47
50
  projectId?: ProjectId;
48
51
  publishableClientKey?: string;
49
52
  urls?: Partial<HandlerUrls>;
@@ -43,7 +43,10 @@ type OAuthScopesOnSignIn = {
43
43
  type ProjectCurrentUser<ProjectId> = ProjectId extends "internal" ? CurrentInternalUser : CurrentUser;
44
44
  type ProjectCurrentServerUser<ProjectId> = ProjectId extends "internal" ? CurrentInternalServerUser : CurrentServerUser;
45
45
  type StackClientAppConstructorOptions<HasTokenStore extends boolean, ProjectId extends string> = {
46
- baseUrl?: string;
46
+ baseUrl?: string | {
47
+ browser: string;
48
+ server: string;
49
+ };
47
50
  projectId?: ProjectId;
48
51
  publishableClientKey?: string;
49
52
  urls?: Partial<HandlerUrls>;
@@ -39,7 +39,6 @@ __export(stack_app_exports, {
39
39
  });
40
40
  module.exports = __toCommonJS(stack_app_exports);
41
41
  var import_browser = require("@simplewebauthn/browser");
42
- var import_stack_sc = require("@stackframe/stack-sc");
43
42
  var import_stack_shared = require("@stackframe/stack-shared");
44
43
  var import_production_mode = require("@stackframe/stack-shared/dist/helpers/production-mode");
45
44
  var import_sessions = require("@stackframe/stack-shared/dist/sessions");
@@ -63,8 +62,14 @@ var import_react2 = __toESM(require("react"));
63
62
  var import_url = require("../utils/url");
64
63
  var import_auth = require("./auth");
65
64
  var import_cookie = require("./cookie");
65
+ var sc = __toESM(require("@stackframe/stack-sc"));
66
+ var isReactServer2 = false;
67
+ isReactServer2 = sc.isReactServer;
66
68
  var NextNavigation = (0, import_compile_time.scrambleDuringCompileTime)(NextNavigationUnscrambled);
67
- var clientVersion = "js @stackframe/stack@2.7.16";
69
+ var clientVersion = "js @stackframe/stack@2.7.18";
70
+ if (clientVersion.startsWith("STACK_COMPILE_TIME")) {
71
+ throw new import_errors.StackAssertionError("Client version was not replaced. Something went wrong during build!");
72
+ }
68
73
  function getUrls(partial) {
69
74
  const handler = partial.handler ?? "/handler";
70
75
  const home = partial.home ?? "/";
@@ -90,10 +95,10 @@ function getUrls(partial) {
90
95
  };
91
96
  }
92
97
  function getDefaultProjectId() {
93
- return (0, import_env.getPublicEnvVar)("NEXT_PUBLIC_STACK_PROJECT_ID") || (0, import_errors.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."));
98
+ return process.env.NEXT_PUBLIC_STACK_PROJECT_ID || (0, import_errors.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."));
94
99
  }
95
100
  function getDefaultPublishableClientKey() {
96
- return (0, import_env.getPublicEnvVar)("NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY") || (0, import_errors.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."));
101
+ return process.env.NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY || (0, import_errors.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."));
97
102
  }
98
103
  function getDefaultSecretServerKey() {
99
104
  return process.env.STACK_SECRET_SERVER_KEY || (0, import_errors.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."));
@@ -101,8 +106,26 @@ function getDefaultSecretServerKey() {
101
106
  function getDefaultSuperSecretAdminKey() {
102
107
  return process.env.STACK_SUPER_SECRET_ADMIN_KEY || (0, import_errors.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."));
103
108
  }
104
- function getDefaultBaseUrl() {
105
- const url = (0, import_env.getPublicEnvVar)("NEXT_PUBLIC_STACK_API_URL") || (0, import_env.getPublicEnvVar)("NEXT_PUBLIC_STACK_URL") || defaultBaseUrl;
109
+ function getBaseUrl(userSpecifiedBaseUrl) {
110
+ let url;
111
+ if (userSpecifiedBaseUrl) {
112
+ if (typeof userSpecifiedBaseUrl === "string") {
113
+ url = userSpecifiedBaseUrl;
114
+ } else {
115
+ if ((0, import_env.isBrowserLike)()) {
116
+ url = userSpecifiedBaseUrl.browser;
117
+ } else {
118
+ url = userSpecifiedBaseUrl.server;
119
+ }
120
+ }
121
+ } else {
122
+ if ((0, import_env.isBrowserLike)()) {
123
+ url = process.env.NEXT_PUBLIC_BROWSER_STACK_API_URL;
124
+ } else {
125
+ url = process.env.NEXT_PUBLIC_SERVER_STACK_API_URL;
126
+ }
127
+ url = url || process.env.NEXT_PUBLIC_STACK_API_URL || process.env.NEXT_PUBLIC_STACK_URL || defaultBaseUrl;
128
+ }
106
129
  return url.endsWith("/") ? url.slice(0, -1) : url;
107
130
  }
108
131
  var defaultBaseUrl = "https://api.stack-auth.com";
@@ -254,7 +277,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
254
277
  this._interface = _options.interface;
255
278
  } else {
256
279
  this._interface = new import_stack_shared.StackClientInterface({
257
- getBaseUrl: () => _options.baseUrl ?? getDefaultBaseUrl(),
280
+ getBaseUrl: () => getBaseUrl(_options.baseUrl),
258
281
  projectId: _options.projectId ?? getDefaultProjectId(),
259
282
  clientVersion,
260
283
  publishableClientKey: _options.publishableClientKey ?? getDefaultPublishableClientKey()
@@ -937,7 +960,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
937
960
  if (this._redirectMethod === "none") {
938
961
  return;
939
962
  }
940
- if (import_stack_sc.isReactServer && this._redirectMethod === "nextjs") {
963
+ if (isReactServer2 && this._redirectMethod === "nextjs") {
941
964
  NextNavigation.redirect(options.url.toString(), options.replace ? NextNavigation.RedirectType.replace : NextNavigation.RedirectType.push);
942
965
  } else {
943
966
  if (options.replace) {
@@ -961,7 +984,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
961
984
  }
962
985
  if (!options?.noRedirectBack) {
963
986
  if (handlerName === "afterSignIn" || handlerName === "afterSignUp") {
964
- if (import_stack_sc.isReactServer || typeof window === "undefined") {
987
+ if (isReactServer2 || typeof window === "undefined") {
965
988
  try {
966
989
  await this._checkFeatureSupport("rsc-handler-" + handlerName, {});
967
990
  } catch (e) {
@@ -971,7 +994,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
971
994
  url = queryParams.get("after_auth_return_to") || url;
972
995
  }
973
996
  } else if (handlerName === "signIn" || handlerName === "signUp") {
974
- if (import_stack_sc.isReactServer || typeof window === "undefined") {
997
+ if (isReactServer2 || typeof window === "undefined") {
975
998
  try {
976
999
  await this._checkFeatureSupport("rsc-handler-" + handlerName, {});
977
1000
  } catch (e) {
@@ -1439,12 +1462,15 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1439
1462
  oauthScopesOnSignIn: options.oauthScopesOnSignIn
1440
1463
  } : {
1441
1464
  interface: new import_stack_shared.StackServerInterface({
1442
- getBaseUrl: () => options.baseUrl ?? getDefaultBaseUrl(),
1465
+ getBaseUrl: () => getBaseUrl(options.baseUrl),
1443
1466
  projectId: options.projectId ?? getDefaultProjectId(),
1444
1467
  clientVersion,
1445
1468
  publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
1446
1469
  secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey()
1447
1470
  }),
1471
+ baseUrl: options.baseUrl,
1472
+ projectId: options.projectId,
1473
+ publishableClientKey: options.publishableClientKey,
1448
1474
  tokenStore: options.tokenStore,
1449
1475
  urls: options.urls ?? {},
1450
1476
  oauthScopesOnSignIn: options.oauthScopesOnSignIn ?? {}
@@ -1940,7 +1966,7 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
1940
1966
  constructor(options) {
1941
1967
  super({
1942
1968
  interface: new import_stack_shared.StackAdminInterface({
1943
- getBaseUrl: () => options.baseUrl ?? getDefaultBaseUrl(),
1969
+ getBaseUrl: () => getBaseUrl(options.baseUrl),
1944
1970
  projectId: options.projectId ?? getDefaultProjectId(),
1945
1971
  clientVersion,
1946
1972
  ..."projectOwnerSession" in options ? {
@@ -1951,6 +1977,8 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
1951
1977
  superSecretAdminKey: options.superSecretAdminKey ?? getDefaultSuperSecretAdminKey()
1952
1978
  }
1953
1979
  }),
1980
+ baseUrl: options.baseUrl,
1981
+ projectId: options.projectId,
1954
1982
  tokenStore: options.tokenStore,
1955
1983
  urls: options.urls,
1956
1984
  oauthScopesOnSignIn: options.oauthScopesOnSignIn