@stackframe/stack 2.7.12 → 2.7.14
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 +20 -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/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.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/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.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 +69 -36
- 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 +12 -8
- package/dist/lib/stack-app.d.ts +12 -8
- package/dist/lib/stack-app.js +68 -35
- 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 +0 -35
- package/dist/utils/email.js.map +0 -1
package/dist/lib/stack-app.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ type RequestLike = {
|
|
|
14
14
|
get: (name: string) => string | null;
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
|
+
type RedirectMethod = "window" | "nextjs" | "none";
|
|
17
18
|
type TokenStoreInit<HasTokenStore extends boolean = boolean> = HasTokenStore extends true ? ("cookie" | "nextjs-cookie" | "memory" | RequestLike | {
|
|
18
19
|
accessToken: string;
|
|
19
20
|
refreshToken: string;
|
|
@@ -48,6 +49,7 @@ type StackClientAppConstructorOptions<HasTokenStore extends boolean, ProjectId e
|
|
|
48
49
|
urls?: Partial<HandlerUrls>;
|
|
49
50
|
oauthScopesOnSignIn?: Partial<OAuthScopesOnSignIn>;
|
|
50
51
|
tokenStore: TokenStoreInit<HasTokenStore>;
|
|
52
|
+
redirectMethod?: RedirectMethod;
|
|
51
53
|
/**
|
|
52
54
|
* By default, the Stack app will automatically prefetch some data from Stack's server when this app is first
|
|
53
55
|
* constructed. This improves the performance of your app, but will create network requests that are unnecessary if
|
|
@@ -184,7 +186,9 @@ type Auth = {
|
|
|
184
186
|
accessToken: string | null;
|
|
185
187
|
refreshToken: string | null;
|
|
186
188
|
}>;
|
|
187
|
-
registerPasskey(
|
|
189
|
+
registerPasskey(options?: {
|
|
190
|
+
hostname?: string;
|
|
191
|
+
}): Promise<Result<undefined, KnownErrors["PasskeyRegistrationFailed"] | KnownErrors["PasskeyWebAuthnError"]>>;
|
|
188
192
|
};
|
|
189
193
|
/**
|
|
190
194
|
* ```
|
|
@@ -307,7 +311,7 @@ type UserUpdateOptions = {
|
|
|
307
311
|
passkeyAuthEnabled?: boolean;
|
|
308
312
|
};
|
|
309
313
|
type ServerBaseUser = {
|
|
310
|
-
setPrimaryEmail(email: string, options?: {
|
|
314
|
+
setPrimaryEmail(email: string | null, options?: {
|
|
311
315
|
verified?: boolean | undefined;
|
|
312
316
|
}): Promise<void>;
|
|
313
317
|
readonly lastActiveAt: Date;
|
|
@@ -339,7 +343,7 @@ type ServerUser = ServerBaseUser & BaseUser & UserExtra;
|
|
|
339
343
|
type CurrentServerUser = Auth & ServerUser;
|
|
340
344
|
type CurrentInternalServerUser = CurrentServerUser & InternalUserExtra;
|
|
341
345
|
type ServerUserUpdateOptions = {
|
|
342
|
-
primaryEmail?: string;
|
|
346
|
+
primaryEmail?: string | null;
|
|
343
347
|
primaryEmailVerified?: boolean;
|
|
344
348
|
primaryEmailAuthEnabled?: boolean;
|
|
345
349
|
clientReadOnlyMetadata?: ReadonlyJson;
|
|
@@ -347,7 +351,7 @@ type ServerUserUpdateOptions = {
|
|
|
347
351
|
password?: string;
|
|
348
352
|
} & UserUpdateOptions;
|
|
349
353
|
type ServerUserCreateOptions = {
|
|
350
|
-
primaryEmail?: string;
|
|
354
|
+
primaryEmail?: string | null;
|
|
351
355
|
primaryEmailAuthEnabled?: boolean;
|
|
352
356
|
password?: string;
|
|
353
357
|
otpAuthEnabled?: boolean;
|
|
@@ -699,12 +703,12 @@ type StackServerApp<HasTokenStore extends boolean = boolean, ProjectId extends s
|
|
|
699
703
|
or: 'throw';
|
|
700
704
|
}): Promise<ProjectCurrentServerUser<ProjectId>>;
|
|
701
705
|
getUser(options?: GetUserOptions<HasTokenStore>): Promise<ProjectCurrentServerUser<ProjectId> | null>;
|
|
702
|
-
listUsers(options?: ServerListUsersOptions): Promise<ServerUser[] & {
|
|
703
|
-
nextCursor: string | null;
|
|
704
|
-
}>;
|
|
705
706
|
useUsers(options?: ServerListUsersOptions): ServerUser[] & {
|
|
706
707
|
nextCursor: string | null;
|
|
707
708
|
};
|
|
709
|
+
listUsers(options?: ServerListUsersOptions): Promise<ServerUser[] & {
|
|
710
|
+
nextCursor: string | null;
|
|
711
|
+
}>;
|
|
708
712
|
} & AsyncStoreProperty<"user", [id: string], ServerUser | null, false> & Omit<AsyncStoreProperty<"users", [], ServerUser[], true>, "listUsers" | "useUsers"> & AsyncStoreProperty<"team", [id: string], ServerTeam | null, false> & AsyncStoreProperty<"teams", [], ServerTeam[], true> & StackClientApp<HasTokenStore, ProjectId>);
|
|
709
713
|
declare const StackServerApp: StackServerAppConstructor;
|
|
710
714
|
type StackAdminAppConstructor = {
|
|
@@ -757,4 +761,4 @@ type EmailConfig = {
|
|
|
757
761
|
senderName: string;
|
|
758
762
|
};
|
|
759
763
|
|
|
760
|
-
export { type AdminDomainConfig, type AdminEmailConfig, type AdminOAuthProviderConfig, type AdminOwnedProject, type AdminProject, type AdminProjectConfig, type AdminProjectConfigUpdateOptions, type AdminProjectCreateOptions, type AdminProjectUpdateOptions, type AdminTeamPermission, type AdminTeamPermissionDefinition, type AdminTeamPermissionDefinitionCreateOptions, type AdminTeamPermissionDefinitionUpdateOptions, type ApiKey, type ApiKeyBase, type ApiKeyBaseCrudRead, type ApiKeyCreateOptions, type ApiKeyFirstView, type Connection, type CurrentInternalServerUser, type CurrentInternalUser, type CurrentServerUser, type CurrentUser, type EditableTeamMemberProfile, type GetUserOptions, type HandlerUrls, type OAuthConnection, type OAuthProviderConfig, type OAuthScopesOnSignIn, type Project, type ProjectConfig, type ServerListUsersOptions, type ServerTeam, type ServerTeamCreateOptions, type ServerTeamMemberProfile, type ServerTeamUpdateOptions, type ServerTeamUser, type ServerUser, StackAdminApp, type StackAdminAppConstructorOptions, StackClientApp, type StackClientAppConstructorOptions, type StackClientAppJson, StackServerApp, type StackServerAppConstructorOptions, type Team, type TeamCreateOptions, type TeamInvitation, type TeamMemberProfile, type TeamPermission, type TeamUpdateOptions, type TeamUser, type TokenStoreInit, type User, serverTeamPermissionDefinitionCreateOptionsToCrud, serverTeamPermissionDefinitionUpdateOptionsToCrud, stackAppInternalsSymbol };
|
|
764
|
+
export { type AdminDomainConfig, type AdminEmailConfig, type AdminOAuthProviderConfig, type AdminOwnedProject, type AdminProject, type AdminProjectConfig, type AdminProjectConfigUpdateOptions, type AdminProjectCreateOptions, type AdminProjectUpdateOptions, type AdminTeamPermission, type AdminTeamPermissionDefinition, type AdminTeamPermissionDefinitionCreateOptions, type AdminTeamPermissionDefinitionUpdateOptions, type ApiKey, type ApiKeyBase, type ApiKeyBaseCrudRead, type ApiKeyCreateOptions, type ApiKeyFirstView, type Connection, type CurrentInternalServerUser, type CurrentInternalUser, type CurrentServerUser, type CurrentUser, type EditableTeamMemberProfile, type GetUserOptions, type HandlerUrls, type OAuthConnection, type OAuthProviderConfig, type OAuthScopesOnSignIn, type Project, type ProjectConfig, type ServerListUsersOptions, type ServerTeam, type ServerTeamCreateOptions, type ServerTeamMemberProfile, type ServerTeamUpdateOptions, type ServerTeamUser, type ServerUser, StackAdminApp, type StackAdminAppConstructor, type StackAdminAppConstructorOptions, StackClientApp, type StackClientAppConstructor, type StackClientAppConstructorOptions, type StackClientAppJson, StackServerApp, type StackServerAppConstructor, type StackServerAppConstructorOptions, type Team, type TeamCreateOptions, type TeamInvitation, type TeamMemberProfile, type TeamPermission, type TeamUpdateOptions, type TeamUser, type TokenStoreInit, type User, serverTeamPermissionDefinitionCreateOptionsToCrud, serverTeamPermissionDefinitionUpdateOptionsToCrud, stackAppInternalsSymbol };
|
package/dist/lib/stack-app.js
CHANGED
|
@@ -64,7 +64,7 @@ var import_url = require("../utils/url");
|
|
|
64
64
|
var import_auth = require("./auth");
|
|
65
65
|
var import_cookie = require("./cookie");
|
|
66
66
|
var NextNavigation = (0, import_compile_time.scrambleDuringCompileTime)(NextNavigationUnscrambled);
|
|
67
|
-
var clientVersion = "js @stackframe/stack@2.7.
|
|
67
|
+
var clientVersion = "js @stackframe/stack@2.7.14";
|
|
68
68
|
function getUrls(partial) {
|
|
69
69
|
const handler = partial.handler ?? "/handler";
|
|
70
70
|
const home = partial.home ?? "/";
|
|
@@ -89,18 +89,6 @@ function getUrls(partial) {
|
|
|
89
89
|
...(0, import_objects.filterUndefined)(partial)
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
|
-
async function _redirectTo(url, options) {
|
|
93
|
-
if (import_stack_sc.isReactServer) {
|
|
94
|
-
NextNavigation.redirect(url.toString(), options?.replace ? NextNavigation.RedirectType.replace : NextNavigation.RedirectType.push);
|
|
95
|
-
} else {
|
|
96
|
-
if (options?.replace) {
|
|
97
|
-
window.location.replace(url);
|
|
98
|
-
} else {
|
|
99
|
-
window.location.assign(url);
|
|
100
|
-
}
|
|
101
|
-
await (0, import_promises.wait)(2e3);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
92
|
function getDefaultProjectId() {
|
|
105
93
|
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."));
|
|
106
94
|
}
|
|
@@ -114,7 +102,8 @@ function getDefaultSuperSecretAdminKey() {
|
|
|
114
102
|
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."));
|
|
115
103
|
}
|
|
116
104
|
function getDefaultBaseUrl() {
|
|
117
|
-
|
|
105
|
+
const url = process.env.NEXT_PUBLIC_STACK_API_URL || process.env.NEXT_PUBLIC_STACK_URL || defaultBaseUrl;
|
|
106
|
+
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
118
107
|
}
|
|
119
108
|
var defaultBaseUrl = "https://api.stack-auth.com";
|
|
120
109
|
function createEmptyTokenStore() {
|
|
@@ -272,6 +261,8 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
272
261
|
});
|
|
273
262
|
}
|
|
274
263
|
this._tokenStoreInit = _options.tokenStore;
|
|
264
|
+
this._redirectMethod = _options.redirectMethod || "none";
|
|
265
|
+
this._redirectMethod = _options.redirectMethod || "nextjs";
|
|
275
266
|
this._urlOptions = _options.urls ?? {};
|
|
276
267
|
this._oauthScopesOnSignIn = _options.oauthScopesOnSignIn ?? {};
|
|
277
268
|
if (_options.uniqueIdentifier) {
|
|
@@ -285,6 +276,13 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
285
276
|
}
|
|
286
277
|
}
|
|
287
278
|
}
|
|
279
|
+
async _createCookieHelper() {
|
|
280
|
+
if (this._tokenStoreInit === "nextjs-cookie" || this._tokenStoreInit === "cookie") {
|
|
281
|
+
return await (0, import_cookie.createCookieHelper)();
|
|
282
|
+
} else {
|
|
283
|
+
return await (0, import_cookie.createEmptyCookieHelper)();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
288
286
|
async _getUserOAuthConnectionCacheFn(options) {
|
|
289
287
|
const user = await options.getUser();
|
|
290
288
|
let hasConnection = true;
|
|
@@ -522,7 +520,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
522
520
|
return session;
|
|
523
521
|
}
|
|
524
522
|
async _getSession(overrideTokenStoreInit) {
|
|
525
|
-
const tokenStore = this._getOrCreateTokenStore(await
|
|
523
|
+
const tokenStore = this._getOrCreateTokenStore(await this._createCookieHelper(), overrideTokenStoreInit);
|
|
526
524
|
return this._getSessionFromTokenStore(tokenStore);
|
|
527
525
|
}
|
|
528
526
|
_useSession(overrideTokenStoreInit) {
|
|
@@ -540,7 +538,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
540
538
|
if (!("accessToken" in tokens) || !("refreshToken" in tokens)) {
|
|
541
539
|
throw new import_errors.StackAssertionError("Invalid tokens object; can't sign in with this", { tokens });
|
|
542
540
|
}
|
|
543
|
-
const tokenStore = this._getOrCreateTokenStore(await
|
|
541
|
+
const tokenStore = this._getOrCreateTokenStore(await this._createCookieHelper());
|
|
544
542
|
tokenStore.set(tokens);
|
|
545
543
|
}
|
|
546
544
|
_hasPersistentTokenStore(overrideTokenStoreInit) {
|
|
@@ -610,8 +608,8 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
610
608
|
clientMetadata: crud.client_metadata,
|
|
611
609
|
clientReadOnlyMetadata: crud.client_read_only_metadata,
|
|
612
610
|
async inviteUser(options) {
|
|
613
|
-
if (!options.callbackUrl &&
|
|
614
|
-
throw new Error("Cannot invite user without a callback URL from the server. Make sure you pass the `callbackUrl` option: `inviteUser({ email, callbackUrl: ... })`");
|
|
611
|
+
if (!options.callbackUrl && !await app._getCurrentUrl()) {
|
|
612
|
+
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: ... })`");
|
|
615
613
|
}
|
|
616
614
|
await app._interface.sendTeamInvitation({
|
|
617
615
|
teamId: crud.id,
|
|
@@ -691,7 +689,11 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
691
689
|
const tokens = await this.currentSession.getTokens();
|
|
692
690
|
return tokens;
|
|
693
691
|
},
|
|
694
|
-
async registerPasskey() {
|
|
692
|
+
async registerPasskey(options) {
|
|
693
|
+
const hostname = (await app._getCurrentUrl())?.hostname;
|
|
694
|
+
if (!hostname) {
|
|
695
|
+
throw new import_errors.StackAssertionError("hostname must be provided if the Stack App does not have a redirect method");
|
|
696
|
+
}
|
|
695
697
|
const initiationResult = await app._interface.initiatePasskeyRegistration({}, session);
|
|
696
698
|
if (initiationResult.status !== "ok") {
|
|
697
699
|
return import_results.Result.error(new import_stack_shared.KnownErrors.PasskeyRegistrationFailed("Failed to get initiation options for passkey registration"));
|
|
@@ -700,7 +702,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
700
702
|
if (options_json.rp.id !== "THIS_VALUE_WILL_BE_REPLACED.example.com") {
|
|
701
703
|
throw new import_errors.StackAssertionError(`Expected returned RP ID from server to equal sentinel, but found ${options_json.rp.id}`);
|
|
702
704
|
}
|
|
703
|
-
options_json.rp.id =
|
|
705
|
+
options_json.rp.id = hostname;
|
|
704
706
|
let attResp;
|
|
705
707
|
try {
|
|
706
708
|
attResp = await (0, import_browser.startRegistration)({ optionsJSON: options_json });
|
|
@@ -839,8 +841,8 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
839
841
|
if (!crud.primary_email) {
|
|
840
842
|
throw new import_errors.StackAssertionError("User does not have a primary email");
|
|
841
843
|
}
|
|
842
|
-
if (!options?.callbackUrl &&
|
|
843
|
-
throw new Error("Cannot send verification email without a callback URL from the server. Make sure you pass the `callbackUrl` option: `sendVerificationEmail({ callbackUrl: ... })`");
|
|
844
|
+
if (!options?.callbackUrl && !await app._getCurrentUrl()) {
|
|
845
|
+
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: ... })`");
|
|
844
846
|
}
|
|
845
847
|
return await app._interface.sendVerificationEmail(crud.primary_email, options?.callbackUrl ?? (0, import_url.constructRedirectUrl)(app.urls.emailVerification), session);
|
|
846
848
|
},
|
|
@@ -928,11 +930,32 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
928
930
|
get urls() {
|
|
929
931
|
return getUrls(this._urlOptions);
|
|
930
932
|
}
|
|
933
|
+
async _getCurrentUrl() {
|
|
934
|
+
if (this._redirectMethod === "none") {
|
|
935
|
+
return null;
|
|
936
|
+
}
|
|
937
|
+
return new URL(window.location.href);
|
|
938
|
+
}
|
|
939
|
+
async _redirectTo(options) {
|
|
940
|
+
if (this._redirectMethod === "none") {
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
if (import_stack_sc.isReactServer && this._redirectMethod === "nextjs") {
|
|
944
|
+
NextNavigation.redirect(options.url.toString(), options.replace ? NextNavigation.RedirectType.replace : NextNavigation.RedirectType.push);
|
|
945
|
+
} else {
|
|
946
|
+
if (options.replace) {
|
|
947
|
+
window.location.replace(options.url);
|
|
948
|
+
} else {
|
|
949
|
+
window.location.assign(options.url);
|
|
950
|
+
}
|
|
951
|
+
await (0, import_promises.wait)(2e3);
|
|
952
|
+
}
|
|
953
|
+
}
|
|
931
954
|
async _redirectIfTrusted(url, options) {
|
|
932
955
|
if (!await this._isTrusted(url)) {
|
|
933
956
|
throw new Error(`Redirect URL ${url} is not trusted; should be relative.`);
|
|
934
957
|
}
|
|
935
|
-
return await _redirectTo(url, options);
|
|
958
|
+
return await this._redirectTo({ url, ...options });
|
|
936
959
|
}
|
|
937
960
|
async _redirectToHandler(handlerName, options) {
|
|
938
961
|
let url = this.urls[handlerName];
|
|
@@ -1016,14 +1039,14 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1016
1039
|
return await this._redirectToHandler("teamInvitation", options);
|
|
1017
1040
|
}
|
|
1018
1041
|
async sendForgotPasswordEmail(email, options) {
|
|
1019
|
-
if (!options?.callbackUrl &&
|
|
1020
|
-
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: ... })`");
|
|
1042
|
+
if (!options?.callbackUrl && !await this._getCurrentUrl()) {
|
|
1043
|
+
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: ... })`");
|
|
1021
1044
|
}
|
|
1022
1045
|
return await this._interface.sendForgotPasswordEmail(email, options?.callbackUrl ?? (0, import_url.constructRedirectUrl)(this.urls.passwordReset));
|
|
1023
1046
|
}
|
|
1024
1047
|
async sendMagicLinkEmail(email, options) {
|
|
1025
|
-
if (!options?.callbackUrl &&
|
|
1026
|
-
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: ... })`");
|
|
1048
|
+
if (!options?.callbackUrl && !await this._getCurrentUrl()) {
|
|
1049
|
+
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: ... })`");
|
|
1027
1050
|
}
|
|
1028
1051
|
return await this._interface.sendMagicLinkEmail(email, options?.callbackUrl ?? (0, import_url.constructRedirectUrl)(this.urls.magicLinkCallback));
|
|
1029
1052
|
}
|
|
@@ -1120,6 +1143,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1120
1143
|
return res;
|
|
1121
1144
|
}
|
|
1122
1145
|
async signInWithOAuth(provider) {
|
|
1146
|
+
if (typeof window === "undefined") {
|
|
1147
|
+
throw new Error("signInWithOAuth can currently only be called in a browser environment");
|
|
1148
|
+
}
|
|
1123
1149
|
this._ensurePersistentTokenStore();
|
|
1124
1150
|
await (0, import_auth.signInWithOAuth)(
|
|
1125
1151
|
this._interface,
|
|
@@ -1263,6 +1289,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1263
1289
|
}
|
|
1264
1290
|
}
|
|
1265
1291
|
async callOAuthCallback() {
|
|
1292
|
+
if (typeof window === "undefined") {
|
|
1293
|
+
throw new Error("callOAuthCallback can currently only be called in a browser environment");
|
|
1294
|
+
}
|
|
1266
1295
|
this._ensurePersistentTokenStore();
|
|
1267
1296
|
let result;
|
|
1268
1297
|
try {
|
|
@@ -1272,13 +1301,15 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1272
1301
|
} catch (e) {
|
|
1273
1302
|
if (e instanceof import_stack_shared.KnownErrors.InvalidTotpCode) {
|
|
1274
1303
|
alert("Invalid TOTP code. Please try signing in again.");
|
|
1304
|
+
return false;
|
|
1305
|
+
} else {
|
|
1306
|
+
throw e;
|
|
1275
1307
|
}
|
|
1276
|
-
throw e;
|
|
1277
1308
|
}
|
|
1278
1309
|
if (result.status === "ok" && result.data) {
|
|
1279
1310
|
await this._signInToAccountWithTokens(result.data);
|
|
1280
1311
|
if ("afterCallbackRedirectUrl" in result.data && result.data.afterCallbackRedirectUrl) {
|
|
1281
|
-
await _redirectTo(result.data.afterCallbackRedirectUrl,
|
|
1312
|
+
await this._redirectTo({ url: result.data.afterCallbackRedirectUrl, replace: true });
|
|
1282
1313
|
return true;
|
|
1283
1314
|
} else if (result.data.newUser) {
|
|
1284
1315
|
await this.redirectToAfterSignUp({ replace: true });
|
|
@@ -1294,7 +1325,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1294
1325
|
await import_stores.storeLock.withWriteLock(async () => {
|
|
1295
1326
|
await this._interface.signOut(session);
|
|
1296
1327
|
if (options?.redirectUrl) {
|
|
1297
|
-
await _redirectTo(options.redirectUrl);
|
|
1328
|
+
await this._redirectTo({ url: options.redirectUrl, replace: true });
|
|
1298
1329
|
} else {
|
|
1299
1330
|
await this.redirectToAfterSignOut();
|
|
1300
1331
|
}
|
|
@@ -1521,8 +1552,8 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1521
1552
|
isPrimary: crud.is_primary,
|
|
1522
1553
|
usedForAuth: crud.used_for_auth,
|
|
1523
1554
|
async sendVerificationEmail(options) {
|
|
1524
|
-
if (!options?.callbackUrl &&
|
|
1525
|
-
throw new Error("Cannot send verification email without a callback URL from the server. Make sure you pass the `callbackUrl` option: `sendVerificationEmail({ callbackUrl: ... })`");
|
|
1555
|
+
if (!options?.callbackUrl && !await app._getCurrentUrl()) {
|
|
1556
|
+
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: ... })`");
|
|
1526
1557
|
}
|
|
1527
1558
|
await app._interface.sendServerContactChannelVerificationEmail(userId, crud.id, options?.callbackUrl ?? (0, import_url.constructRedirectUrl)(app.urls.emailVerification));
|
|
1528
1559
|
},
|
|
@@ -1753,8 +1784,8 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1753
1784
|
await app._serverTeamMemberProfilesCache.refresh([crud.id]);
|
|
1754
1785
|
},
|
|
1755
1786
|
async inviteUser(options) {
|
|
1756
|
-
if (!options.callbackUrl &&
|
|
1757
|
-
throw new Error("Cannot invite user without a callback URL from the server. Make sure you pass the `callbackUrl` option: `inviteUser({ email, callbackUrl: ... })`");
|
|
1787
|
+
if (!options.callbackUrl && !await app._getCurrentUrl()) {
|
|
1788
|
+
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: ... })`");
|
|
1758
1789
|
}
|
|
1759
1790
|
await app._interface.sendServerTeamInvitation({
|
|
1760
1791
|
teamId: crud.id,
|
|
@@ -1902,7 +1933,9 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1902
1933
|
async _refreshUsers() {
|
|
1903
1934
|
await Promise.all([
|
|
1904
1935
|
super._refreshUsers(),
|
|
1905
|
-
this.
|
|
1936
|
+
this._serverUserCache.refreshWhere(() => true),
|
|
1937
|
+
this._serverUsersCache.refreshWhere(() => true),
|
|
1938
|
+
this._serverContactChannelsCache.refreshWhere(() => true)
|
|
1906
1939
|
]);
|
|
1907
1940
|
}
|
|
1908
1941
|
};
|