@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.
- package/CHANGELOG.md +39 -0
- package/dist/components/credential-sign-in.js.map +1 -1
- package/dist/components/credential-sign-up.js.map +1 -1
- package/dist/components/elements/form-warning.js.map +1 -1
- package/dist/components/elements/maybe-full-page.js.map +1 -1
- package/dist/components/elements/separator-with-text.js.map +1 -1
- package/dist/components/elements/sidebar-layout.js.map +1 -1
- package/dist/components/elements/ssr-layout-effect.js.map +1 -1
- package/dist/components/elements/user-avatar.js.map +1 -1
- package/dist/components/iframe-preventer.d.mts +8 -0
- package/dist/components/iframe-preventer.d.ts +8 -0
- package/dist/{utils/email.js → components/iframe-preventer.js} +28 -11
- package/dist/components/iframe-preventer.js.map +1 -0
- package/dist/components/magic-link-sign-in.js.map +1 -1
- package/dist/components/message-cards/known-error-message-card.js.map +1 -1
- package/dist/components/message-cards/message-card.js.map +1 -1
- package/dist/components/message-cards/predefined-message-card.js.map +1 -1
- package/dist/components/oauth-button-group.js.map +1 -1
- package/dist/components/oauth-button.js.map +1 -1
- package/dist/components/passkey-button.js.map +1 -1
- package/dist/components/profile-image-editor.js.map +1 -1
- package/dist/components/selected-team-switcher.js.map +1 -1
- package/dist/components/team-icon.js.map +1 -1
- package/dist/components/user-button.js.map +1 -1
- package/dist/components-page/account-settings.js +9 -1
- package/dist/components-page/account-settings.js.map +1 -1
- package/dist/components-page/auth-page.js.map +1 -1
- package/dist/components-page/email-verification.js.map +1 -1
- package/dist/components-page/error-page.js.map +1 -1
- package/dist/components-page/forgot-password.js.map +1 -1
- package/dist/components-page/magic-link-callback.js.map +1 -1
- package/dist/components-page/oauth-callback.js.map +1 -1
- package/dist/components-page/password-reset.js.map +1 -1
- package/dist/components-page/sign-in.js.map +1 -1
- package/dist/components-page/sign-out.js.map +1 -1
- package/dist/components-page/sign-up.js.map +1 -1
- package/dist/components-page/stack-handler.js +3 -2
- package/dist/components-page/stack-handler.js.map +1 -1
- package/dist/components-page/team-creation.js.map +1 -1
- package/dist/components-page/team-invitation.js.map +1 -1
- package/dist/esm/components/credential-sign-in.js.map +1 -1
- package/dist/esm/components/credential-sign-up.js.map +1 -1
- package/dist/esm/components/elements/form-warning.js.map +1 -1
- package/dist/esm/components/elements/maybe-full-page.js.map +1 -1
- package/dist/esm/components/elements/separator-with-text.js.map +1 -1
- package/dist/esm/components/elements/sidebar-layout.js.map +1 -1
- package/dist/esm/components/elements/ssr-layout-effect.js.map +1 -1
- package/dist/esm/components/elements/user-avatar.js.map +1 -1
- package/dist/esm/components/iframe-preventer.js +28 -0
- package/dist/esm/components/iframe-preventer.js.map +1 -0
- package/dist/esm/components/magic-link-sign-in.js.map +1 -1
- package/dist/esm/components/message-cards/known-error-message-card.js.map +1 -1
- package/dist/esm/components/message-cards/message-card.js.map +1 -1
- package/dist/esm/components/message-cards/predefined-message-card.js.map +1 -1
- package/dist/esm/components/oauth-button-group.js.map +1 -1
- package/dist/esm/components/oauth-button.js.map +1 -1
- package/dist/esm/components/passkey-button.js.map +1 -1
- package/dist/esm/components/profile-image-editor.js.map +1 -1
- package/dist/esm/components/selected-team-switcher.js.map +1 -1
- package/dist/esm/components/team-icon.js.map +1 -1
- package/dist/esm/components/user-button.js.map +1 -1
- package/dist/esm/components-page/account-settings.js +11 -3
- package/dist/esm/components-page/account-settings.js.map +1 -1
- package/dist/esm/components-page/auth-page.js.map +1 -1
- package/dist/esm/components-page/email-verification.js.map +1 -1
- package/dist/esm/components-page/error-page.js.map +1 -1
- package/dist/esm/components-page/forgot-password.js.map +1 -1
- package/dist/esm/components-page/magic-link-callback.js.map +1 -1
- package/dist/esm/components-page/oauth-callback.js.map +1 -1
- package/dist/esm/components-page/password-reset.js.map +1 -1
- package/dist/esm/components-page/sign-in.js.map +1 -1
- package/dist/esm/components-page/sign-out.js.map +1 -1
- package/dist/esm/components-page/sign-up.js.map +1 -1
- package/dist/esm/components-page/stack-handler.js +3 -2
- package/dist/esm/components-page/stack-handler.js.map +1 -1
- package/dist/esm/components-page/team-creation.js.map +1 -1
- package/dist/esm/components-page/team-invitation.js.map +1 -1
- package/dist/esm/generated/global-css.js +1 -1
- package/dist/esm/generated/global-css.js.map +1 -1
- package/dist/esm/generated/quetzal-translations.js.map +1 -1
- package/dist/esm/index.js +3 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/auth.js.map +1 -1
- package/dist/esm/lib/cookie.js +15 -0
- package/dist/esm/lib/cookie.js.map +1 -1
- package/dist/esm/lib/hooks.js +2 -2
- package/dist/esm/lib/hooks.js.map +1 -1
- package/dist/esm/lib/stack-app.js +94 -56
- package/dist/esm/lib/stack-app.js.map +1 -1
- package/dist/esm/lib/translations.js.map +1 -1
- package/dist/esm/providers/stack-provider-client.js.map +1 -1
- package/dist/esm/providers/stack-provider.js.map +1 -1
- package/dist/esm/providers/theme-provider.js.map +1 -1
- package/dist/esm/providers/translation-provider-client.js.map +1 -1
- package/dist/esm/providers/translation-provider.js.map +1 -1
- package/dist/esm/utils/browser-script.js.map +1 -1
- package/dist/esm/utils/constants.js.map +1 -1
- package/dist/esm/utils/url.js +1 -1
- package/dist/esm/utils/url.js.map +1 -1
- package/dist/generated/global-css.d.mts +1 -1
- package/dist/generated/global-css.d.ts +1 -1
- package/dist/generated/global-css.js +1 -1
- package/dist/generated/global-css.js.map +1 -1
- package/dist/generated/quetzal-translations.js.map +1 -1
- package/dist/index.d.mts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/auth.js.map +1 -1
- package/dist/lib/cookie.d.mts +2 -1
- package/dist/lib/cookie.d.ts +2 -1
- package/dist/lib/cookie.js +16 -0
- package/dist/lib/cookie.js.map +1 -1
- package/dist/lib/hooks.js +2 -2
- package/dist/lib/hooks.js.map +1 -1
- package/dist/lib/stack-app.d.mts +19 -9
- package/dist/lib/stack-app.d.ts +19 -9
- package/dist/lib/stack-app.js +92 -54
- package/dist/lib/stack-app.js.map +1 -1
- package/dist/lib/translations.js.map +1 -1
- package/dist/providers/stack-provider-client.js.map +1 -1
- package/dist/providers/stack-provider.js.map +1 -1
- package/dist/providers/theme-provider.js.map +1 -1
- package/dist/providers/translation-provider-client.js.map +1 -1
- package/dist/providers/translation-provider.js.map +1 -1
- package/dist/utils/browser-script.js.map +1 -1
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/url.js +1 -1
- package/dist/utils/url.js.map +1 -1
- package/package.json +10 -13
- package/dist/esm/utils/email.js +0 -10
- package/dist/esm/utils/email.js.map +0 -1
- package/dist/utils/email.d.mts +0 -3
- package/dist/utils/email.d.ts +0 -3
- 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.
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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 &&
|
|
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 =
|
|
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 &&
|
|
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.
|
|
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 &&
|
|
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 &&
|
|
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,
|
|
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.
|
|
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
|
-
|
|
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 &&
|
|
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
|
-
|
|
1579
|
-
|
|
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 &&
|
|
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.
|
|
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
|
-
|
|
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
|
|
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 {
|