@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
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,13 +311,14 @@ 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;
|
|
314
318
|
readonly serverMetadata: any;
|
|
315
319
|
setServerMetadata(metadata: any): Promise<void>;
|
|
316
320
|
setClientReadOnlyMetadata(metadata: any): Promise<void>;
|
|
321
|
+
createTeam(data: Omit<ServerTeamCreateOptions, "creatorUserId">): Promise<ServerTeam>;
|
|
317
322
|
useContactChannels(): ServerContactChannel[];
|
|
318
323
|
listContactChannels(): Promise<ServerContactChannel[]>;
|
|
319
324
|
createContactChannel(data: ServerContactChannelCreateOptions): Promise<ServerContactChannel>;
|
|
@@ -339,7 +344,7 @@ type ServerUser = ServerBaseUser & BaseUser & UserExtra;
|
|
|
339
344
|
type CurrentServerUser = Auth & ServerUser;
|
|
340
345
|
type CurrentInternalServerUser = CurrentServerUser & InternalUserExtra;
|
|
341
346
|
type ServerUserUpdateOptions = {
|
|
342
|
-
primaryEmail?: string;
|
|
347
|
+
primaryEmail?: string | null;
|
|
343
348
|
primaryEmailVerified?: boolean;
|
|
344
349
|
primaryEmailAuthEnabled?: boolean;
|
|
345
350
|
clientReadOnlyMetadata?: ReadonlyJson;
|
|
@@ -347,12 +352,15 @@ type ServerUserUpdateOptions = {
|
|
|
347
352
|
password?: string;
|
|
348
353
|
} & UserUpdateOptions;
|
|
349
354
|
type ServerUserCreateOptions = {
|
|
350
|
-
primaryEmail?: string;
|
|
355
|
+
primaryEmail?: string | null;
|
|
351
356
|
primaryEmailAuthEnabled?: boolean;
|
|
352
357
|
password?: string;
|
|
353
358
|
otpAuthEnabled?: boolean;
|
|
354
359
|
displayName?: string;
|
|
355
360
|
primaryEmailVerified?: boolean;
|
|
361
|
+
clientMetadata?: any;
|
|
362
|
+
clientReadOnlyMetadata?: any;
|
|
363
|
+
serverMetadata?: any;
|
|
356
364
|
};
|
|
357
365
|
type Project = {
|
|
358
366
|
readonly id: string;
|
|
@@ -569,7 +577,9 @@ type ServerListUsersOptions = {
|
|
|
569
577
|
desc?: boolean;
|
|
570
578
|
query?: string;
|
|
571
579
|
};
|
|
572
|
-
type ServerTeamCreateOptions = TeamCreateOptions
|
|
580
|
+
type ServerTeamCreateOptions = TeamCreateOptions & {
|
|
581
|
+
creatorUserId?: string;
|
|
582
|
+
};
|
|
573
583
|
type ServerTeamUpdateOptions = TeamUpdateOptions & {
|
|
574
584
|
clientReadOnlyMetadata?: ReadonlyJson;
|
|
575
585
|
serverMetadata?: ReadonlyJson;
|
|
@@ -699,12 +709,12 @@ type StackServerApp<HasTokenStore extends boolean = boolean, ProjectId extends s
|
|
|
699
709
|
or: 'throw';
|
|
700
710
|
}): Promise<ProjectCurrentServerUser<ProjectId>>;
|
|
701
711
|
getUser(options?: GetUserOptions<HasTokenStore>): Promise<ProjectCurrentServerUser<ProjectId> | null>;
|
|
702
|
-
listUsers(options?: ServerListUsersOptions): Promise<ServerUser[] & {
|
|
703
|
-
nextCursor: string | null;
|
|
704
|
-
}>;
|
|
705
712
|
useUsers(options?: ServerListUsersOptions): ServerUser[] & {
|
|
706
713
|
nextCursor: string | null;
|
|
707
714
|
};
|
|
715
|
+
listUsers(options?: ServerListUsersOptions): Promise<ServerUser[] & {
|
|
716
|
+
nextCursor: string | null;
|
|
717
|
+
}>;
|
|
708
718
|
} & 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
719
|
declare const StackServerApp: StackServerAppConstructor;
|
|
710
720
|
type StackAdminAppConstructor = {
|
|
@@ -757,4 +767,4 @@ type EmailConfig = {
|
|
|
757
767
|
senderName: string;
|
|
758
768
|
};
|
|
759
769
|
|
|
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 };
|
|
770
|
+
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.16";
|
|
68
68
|
function getUrls(partial) {
|
|
69
69
|
const handler = partial.handler ?? "/handler";
|
|
70
70
|
const home = partial.home ?? "/";
|
|
@@ -89,23 +89,11 @@ 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
|
-
return
|
|
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."));
|
|
106
94
|
}
|
|
107
95
|
function getDefaultPublishableClientKey() {
|
|
108
|
-
return
|
|
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."));
|
|
109
97
|
}
|
|
110
98
|
function getDefaultSecretServerKey() {
|
|
111
99
|
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."));
|
|
@@ -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 = (0, import_env.getPublicEnvVar)("NEXT_PUBLIC_STACK_API_URL") || (0, import_env.getPublicEnvVar)("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() {
|
|
@@ -265,13 +254,15 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
265
254
|
this._interface = _options.interface;
|
|
266
255
|
} else {
|
|
267
256
|
this._interface = new import_stack_shared.StackClientInterface({
|
|
268
|
-
|
|
257
|
+
getBaseUrl: () => _options.baseUrl ?? getDefaultBaseUrl(),
|
|
269
258
|
projectId: _options.projectId ?? getDefaultProjectId(),
|
|
270
259
|
clientVersion,
|
|
271
260
|
publishableClientKey: _options.publishableClientKey ?? getDefaultPublishableClientKey()
|
|
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 });
|
|
@@ -801,10 +803,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
801
803
|
return (0, import_react2.useMemo)(() => teams.map((crud2) => app._clientTeamFromCrud(crud2, session)), [teams]);
|
|
802
804
|
},
|
|
803
805
|
async createTeam(data) {
|
|
804
|
-
const crud2 = await app._interface.createClientTeam(
|
|
805
|
-
...teamCreateOptionsToCrud(data),
|
|
806
|
-
creator_user_id: "me"
|
|
807
|
-
}, session);
|
|
806
|
+
const crud2 = await app._interface.createClientTeam(teamCreateOptionsToCrud(data, "me"), session);
|
|
808
807
|
await app._currentUserTeamsCache.refresh([session]);
|
|
809
808
|
return app._clientTeamFromCrud(crud2, session);
|
|
810
809
|
},
|
|
@@ -839,8 +838,8 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
839
838
|
if (!crud.primary_email) {
|
|
840
839
|
throw new import_errors.StackAssertionError("User does not have a primary email");
|
|
841
840
|
}
|
|
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: ... })`");
|
|
841
|
+
if (!options?.callbackUrl && !await app._getCurrentUrl()) {
|
|
842
|
+
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
843
|
}
|
|
845
844
|
return await app._interface.sendVerificationEmail(crud.primary_email, options?.callbackUrl ?? (0, import_url.constructRedirectUrl)(app.urls.emailVerification), session);
|
|
846
845
|
},
|
|
@@ -910,7 +909,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
910
909
|
_getOwnedAdminApp(forProjectId, session) {
|
|
911
910
|
if (!this._ownedAdminApps.has([session, forProjectId])) {
|
|
912
911
|
this._ownedAdminApps.set([session, forProjectId], new _StackAdminAppImpl({
|
|
913
|
-
baseUrl: this._interface.options.
|
|
912
|
+
baseUrl: this._interface.options.getBaseUrl(),
|
|
914
913
|
projectId: forProjectId,
|
|
915
914
|
tokenStore: null,
|
|
916
915
|
projectOwnerSession: session,
|
|
@@ -928,11 +927,32 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
928
927
|
get urls() {
|
|
929
928
|
return getUrls(this._urlOptions);
|
|
930
929
|
}
|
|
930
|
+
async _getCurrentUrl() {
|
|
931
|
+
if (this._redirectMethod === "none") {
|
|
932
|
+
return null;
|
|
933
|
+
}
|
|
934
|
+
return new URL(window.location.href);
|
|
935
|
+
}
|
|
936
|
+
async _redirectTo(options) {
|
|
937
|
+
if (this._redirectMethod === "none") {
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
940
|
+
if (import_stack_sc.isReactServer && this._redirectMethod === "nextjs") {
|
|
941
|
+
NextNavigation.redirect(options.url.toString(), options.replace ? NextNavigation.RedirectType.replace : NextNavigation.RedirectType.push);
|
|
942
|
+
} else {
|
|
943
|
+
if (options.replace) {
|
|
944
|
+
window.location.replace(options.url);
|
|
945
|
+
} else {
|
|
946
|
+
window.location.assign(options.url);
|
|
947
|
+
}
|
|
948
|
+
await (0, import_promises.wait)(2e3);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
931
951
|
async _redirectIfTrusted(url, options) {
|
|
932
952
|
if (!await this._isTrusted(url)) {
|
|
933
953
|
throw new Error(`Redirect URL ${url} is not trusted; should be relative.`);
|
|
934
954
|
}
|
|
935
|
-
return await _redirectTo(url, options);
|
|
955
|
+
return await this._redirectTo({ url, ...options });
|
|
936
956
|
}
|
|
937
957
|
async _redirectToHandler(handlerName, options) {
|
|
938
958
|
let url = this.urls[handlerName];
|
|
@@ -1016,14 +1036,14 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1016
1036
|
return await this._redirectToHandler("teamInvitation", options);
|
|
1017
1037
|
}
|
|
1018
1038
|
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: ... })`");
|
|
1039
|
+
if (!options?.callbackUrl && !await this._getCurrentUrl()) {
|
|
1040
|
+
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
1041
|
}
|
|
1022
1042
|
return await this._interface.sendForgotPasswordEmail(email, options?.callbackUrl ?? (0, import_url.constructRedirectUrl)(this.urls.passwordReset));
|
|
1023
1043
|
}
|
|
1024
1044
|
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: ... })`");
|
|
1045
|
+
if (!options?.callbackUrl && !await this._getCurrentUrl()) {
|
|
1046
|
+
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
1047
|
}
|
|
1028
1048
|
return await this._interface.sendMagicLinkEmail(email, options?.callbackUrl ?? (0, import_url.constructRedirectUrl)(this.urls.magicLinkCallback));
|
|
1029
1049
|
}
|
|
@@ -1120,6 +1140,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1120
1140
|
return res;
|
|
1121
1141
|
}
|
|
1122
1142
|
async signInWithOAuth(provider) {
|
|
1143
|
+
if (typeof window === "undefined") {
|
|
1144
|
+
throw new Error("signInWithOAuth can currently only be called in a browser environment");
|
|
1145
|
+
}
|
|
1123
1146
|
this._ensurePersistentTokenStore();
|
|
1124
1147
|
await (0, import_auth.signInWithOAuth)(
|
|
1125
1148
|
this._interface,
|
|
@@ -1263,6 +1286,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1263
1286
|
}
|
|
1264
1287
|
}
|
|
1265
1288
|
async callOAuthCallback() {
|
|
1289
|
+
if (typeof window === "undefined") {
|
|
1290
|
+
throw new Error("callOAuthCallback can currently only be called in a browser environment");
|
|
1291
|
+
}
|
|
1266
1292
|
this._ensurePersistentTokenStore();
|
|
1267
1293
|
let result;
|
|
1268
1294
|
try {
|
|
@@ -1272,13 +1298,15 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1272
1298
|
} catch (e) {
|
|
1273
1299
|
if (e instanceof import_stack_shared.KnownErrors.InvalidTotpCode) {
|
|
1274
1300
|
alert("Invalid TOTP code. Please try signing in again.");
|
|
1301
|
+
return false;
|
|
1302
|
+
} else {
|
|
1303
|
+
throw e;
|
|
1275
1304
|
}
|
|
1276
|
-
throw e;
|
|
1277
1305
|
}
|
|
1278
1306
|
if (result.status === "ok" && result.data) {
|
|
1279
1307
|
await this._signInToAccountWithTokens(result.data);
|
|
1280
1308
|
if ("afterCallbackRedirectUrl" in result.data && result.data.afterCallbackRedirectUrl) {
|
|
1281
|
-
await _redirectTo(result.data.afterCallbackRedirectUrl,
|
|
1309
|
+
await this._redirectTo({ url: result.data.afterCallbackRedirectUrl, replace: true });
|
|
1282
1310
|
return true;
|
|
1283
1311
|
} else if (result.data.newUser) {
|
|
1284
1312
|
await this.redirectToAfterSignUp({ replace: true });
|
|
@@ -1294,7 +1322,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1294
1322
|
await import_stores.storeLock.withWriteLock(async () => {
|
|
1295
1323
|
await this._interface.signOut(session);
|
|
1296
1324
|
if (options?.redirectUrl) {
|
|
1297
|
-
await _redirectTo(options.redirectUrl);
|
|
1325
|
+
await this._redirectTo({ url: options.redirectUrl, replace: true });
|
|
1298
1326
|
} else {
|
|
1299
1327
|
await this.redirectToAfterSignOut();
|
|
1300
1328
|
}
|
|
@@ -1382,7 +1410,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1382
1410
|
throw new import_errors.StackAssertionError("Cannot serialize to JSON from an application without a publishable client key");
|
|
1383
1411
|
}
|
|
1384
1412
|
return {
|
|
1385
|
-
baseUrl: this.
|
|
1413
|
+
baseUrl: this._options.baseUrl,
|
|
1386
1414
|
projectId: this.projectId,
|
|
1387
1415
|
publishableClientKey: this._interface.options.publishableClientKey,
|
|
1388
1416
|
tokenStore: this._tokenStoreInit,
|
|
@@ -1411,7 +1439,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1411
1439
|
oauthScopesOnSignIn: options.oauthScopesOnSignIn
|
|
1412
1440
|
} : {
|
|
1413
1441
|
interface: new import_stack_shared.StackServerInterface({
|
|
1414
|
-
|
|
1442
|
+
getBaseUrl: () => options.baseUrl ?? getDefaultBaseUrl(),
|
|
1415
1443
|
projectId: options.projectId ?? getDefaultProjectId(),
|
|
1416
1444
|
clientVersion,
|
|
1417
1445
|
publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
|
|
@@ -1521,8 +1549,8 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1521
1549
|
isPrimary: crud.is_primary,
|
|
1522
1550
|
usedForAuth: crud.used_for_auth,
|
|
1523
1551
|
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: ... })`");
|
|
1552
|
+
if (!options?.callbackUrl && !await app._getCurrentUrl()) {
|
|
1553
|
+
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
1554
|
}
|
|
1527
1555
|
await app._interface.sendServerContactChannelVerificationEmail(userId, crud.id, options?.callbackUrl ?? (0, import_url.constructRedirectUrl)(app.urls.emailVerification));
|
|
1528
1556
|
},
|
|
@@ -1613,10 +1641,10 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1613
1641
|
return (0, import_react2.useMemo)(() => teams.map((t) => app._serverTeamFromCrud(t)), [teams]);
|
|
1614
1642
|
},
|
|
1615
1643
|
createTeam: async (data) => {
|
|
1616
|
-
const team = await app._interface.createServerTeam({
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
});
|
|
1644
|
+
const team = await app._interface.createServerTeam(serverTeamCreateOptionsToCrud({
|
|
1645
|
+
creatorUserId: crud.id,
|
|
1646
|
+
...data
|
|
1647
|
+
}));
|
|
1620
1648
|
await app._serverTeamsCache.refresh([void 0]);
|
|
1621
1649
|
return app._serverTeamFromCrud(team);
|
|
1622
1650
|
},
|
|
@@ -1753,8 +1781,8 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1753
1781
|
await app._serverTeamMemberProfilesCache.refresh([crud.id]);
|
|
1754
1782
|
},
|
|
1755
1783
|
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: ... })`");
|
|
1784
|
+
if (!options.callbackUrl && !await app._getCurrentUrl()) {
|
|
1785
|
+
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
1786
|
}
|
|
1759
1787
|
await app._interface.sendServerTeamInvitation({
|
|
1760
1788
|
teamId: crud.id,
|
|
@@ -1902,7 +1930,9 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1902
1930
|
async _refreshUsers() {
|
|
1903
1931
|
await Promise.all([
|
|
1904
1932
|
super._refreshUsers(),
|
|
1905
|
-
this.
|
|
1933
|
+
this._serverUserCache.refreshWhere(() => true),
|
|
1934
|
+
this._serverUsersCache.refreshWhere(() => true),
|
|
1935
|
+
this._serverContactChannelsCache.refreshWhere(() => true)
|
|
1906
1936
|
]);
|
|
1907
1937
|
}
|
|
1908
1938
|
};
|
|
@@ -1910,7 +1940,7 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
|
|
|
1910
1940
|
constructor(options) {
|
|
1911
1941
|
super({
|
|
1912
1942
|
interface: new import_stack_shared.StackAdminInterface({
|
|
1913
|
-
|
|
1943
|
+
getBaseUrl: () => options.baseUrl ?? getDefaultBaseUrl(),
|
|
1914
1944
|
projectId: options.projectId ?? getDefaultProjectId(),
|
|
1915
1945
|
clientVersion,
|
|
1916
1946
|
..."projectOwnerSession" in options ? {
|
|
@@ -2240,7 +2270,10 @@ function serverUserCreateOptionsToCrud(options) {
|
|
|
2240
2270
|
otp_auth_enabled: options.otpAuthEnabled,
|
|
2241
2271
|
primary_email_auth_enabled: options.primaryEmailAuthEnabled,
|
|
2242
2272
|
display_name: options.displayName,
|
|
2243
|
-
primary_email_verified: options.primaryEmailVerified
|
|
2273
|
+
primary_email_verified: options.primaryEmailVerified,
|
|
2274
|
+
client_metadata: options.clientMetadata,
|
|
2275
|
+
client_read_only_metadata: options.clientReadOnlyMetadata,
|
|
2276
|
+
server_metadata: options.serverMetadata
|
|
2244
2277
|
};
|
|
2245
2278
|
}
|
|
2246
2279
|
function adminProjectUpdateOptionsToCrud(options) {
|
|
@@ -2311,14 +2344,19 @@ function teamUpdateOptionsToCrud(options) {
|
|
|
2311
2344
|
client_metadata: options.clientMetadata
|
|
2312
2345
|
};
|
|
2313
2346
|
}
|
|
2314
|
-
function teamCreateOptionsToCrud(options) {
|
|
2347
|
+
function teamCreateOptionsToCrud(options, creatorUserId) {
|
|
2315
2348
|
return {
|
|
2316
2349
|
display_name: options.displayName,
|
|
2317
|
-
profile_image_url: options.profileImageUrl
|
|
2350
|
+
profile_image_url: options.profileImageUrl,
|
|
2351
|
+
creator_user_id: creatorUserId
|
|
2318
2352
|
};
|
|
2319
2353
|
}
|
|
2320
2354
|
function serverTeamCreateOptionsToCrud(options) {
|
|
2321
|
-
return
|
|
2355
|
+
return {
|
|
2356
|
+
display_name: options.displayName,
|
|
2357
|
+
profile_image_url: options.profileImageUrl,
|
|
2358
|
+
creator_user_id: options.creatorUserId
|
|
2359
|
+
};
|
|
2322
2360
|
}
|
|
2323
2361
|
function serverTeamUpdateOptionsToCrud(options) {
|
|
2324
2362
|
return {
|