@stackframe/stack 2.4.21 → 2.4.23
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 +18 -0
- package/dist/components/message-cards/known-error-message-card.d.mts +9 -0
- package/dist/components/message-cards/known-error-message-card.d.ts +9 -0
- package/dist/components/message-cards/known-error-message-card.js +67 -0
- package/dist/components/message-cards/known-error-message-card.js.map +1 -0
- package/dist/components/{message-card.d.mts → message-cards/message-card.d.mts} +5 -1
- package/dist/components/{message-card.d.ts → message-cards/message-card.d.ts} +5 -1
- package/dist/components/{message-card.js → message-cards/message-card.js} +10 -6
- package/dist/components/message-cards/message-card.js.map +1 -0
- package/dist/components/{redirect-message-card.d.mts → message-cards/predefined-message-card.d.mts} +3 -3
- package/dist/components/{redirect-message-card.d.ts → message-cards/predefined-message-card.d.ts} +3 -3
- package/dist/components/{redirect-message-card.js → message-cards/predefined-message-card.js} +32 -29
- package/dist/components/message-cards/predefined-message-card.js.map +1 -0
- package/dist/components/password-reset-inner.js +3 -3
- package/dist/components/password-reset-inner.js.map +1 -1
- package/dist/components-core/index.d.mts +4 -4
- package/dist/components-core/index.d.ts +4 -4
- package/dist/components-page/account-settings.js +2 -2
- package/dist/components-page/account-settings.js.map +1 -1
- package/dist/components-page/auth-page.js +2 -2
- package/dist/components-page/auth-page.js.map +1 -1
- package/dist/components-page/email-verification.js +3 -3
- package/dist/components-page/email-verification.js.map +1 -1
- package/dist/components-page/error-page.d.mts +8 -0
- package/dist/components-page/error-page.d.ts +8 -0
- package/dist/components-page/error-page.js +85 -0
- package/dist/components-page/error-page.js.map +1 -0
- package/dist/components-page/forgot-password.js +3 -3
- package/dist/components-page/forgot-password.js.map +1 -1
- package/dist/components-page/magic-link-callback.js +3 -3
- package/dist/components-page/magic-link-callback.js.map +1 -1
- package/dist/components-page/oauth-callback.js +4 -3
- package/dist/components-page/oauth-callback.js.map +1 -1
- package/dist/components-page/password-reset.js +1 -1
- package/dist/components-page/password-reset.js.map +1 -1
- package/dist/components-page/sign-out.js +2 -2
- package/dist/components-page/sign-out.js.map +1 -1
- package/dist/components-page/stack-handler.js +5 -1
- package/dist/components-page/stack-handler.js.map +1 -1
- package/dist/esm/components/message-cards/known-error-message-card.js +37 -0
- package/dist/esm/components/message-cards/known-error-message-card.js.map +1 -0
- package/dist/esm/components/message-cards/message-card.js +21 -0
- package/dist/esm/components/message-cards/message-card.js.map +1 -0
- package/dist/esm/components/{redirect-message-card.js → message-cards/predefined-message-card.js} +30 -27
- package/dist/esm/components/message-cards/predefined-message-card.js.map +1 -0
- package/dist/esm/components/password-reset-inner.js +3 -3
- package/dist/esm/components/password-reset-inner.js.map +1 -1
- package/dist/esm/components-page/account-settings.js +2 -2
- package/dist/esm/components-page/account-settings.js.map +1 -1
- package/dist/esm/components-page/auth-page.js +2 -2
- package/dist/esm/components-page/auth-page.js.map +1 -1
- package/dist/esm/components-page/email-verification.js +3 -3
- package/dist/esm/components-page/email-verification.js.map +1 -1
- package/dist/esm/components-page/error-page.js +55 -0
- package/dist/esm/components-page/error-page.js.map +1 -0
- package/dist/esm/components-page/forgot-password.js +3 -3
- package/dist/esm/components-page/forgot-password.js.map +1 -1
- package/dist/esm/components-page/magic-link-callback.js +3 -3
- package/dist/esm/components-page/magic-link-callback.js.map +1 -1
- package/dist/esm/components-page/oauth-callback.js +4 -3
- package/dist/esm/components-page/oauth-callback.js.map +1 -1
- package/dist/esm/components-page/password-reset.js +1 -1
- package/dist/esm/components-page/password-reset.js.map +1 -1
- package/dist/esm/components-page/sign-out.js +1 -1
- package/dist/esm/components-page/sign-out.js.map +1 -1
- package/dist/esm/components-page/stack-handler.js +5 -1
- package/dist/esm/components-page/stack-handler.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/auth.js +30 -14
- package/dist/esm/lib/auth.js.map +1 -1
- package/dist/esm/lib/stack-app.js +141 -67
- package/dist/esm/lib/stack-app.js.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/auth.d.mts +13 -3
- package/dist/lib/auth.d.ts +13 -3
- package/dist/lib/auth.js +31 -14
- package/dist/lib/auth.js.map +1 -1
- package/dist/lib/stack-app.d.mts +111 -65
- package/dist/lib/stack-app.d.ts +111 -65
- package/dist/lib/stack-app.js +138 -64
- package/dist/lib/stack-app.js.map +1 -1
- package/dist/providers/component-provider.d.mts +6 -6
- package/dist/providers/component-provider.d.ts +6 -6
- package/package.json +3 -3
- package/dist/components/message-card.js.map +0 -1
- package/dist/components/redirect-message-card.js.map +0 -1
- package/dist/esm/components/message-card.js +0 -17
- package/dist/esm/components/message-card.js.map +0 -1
- package/dist/esm/components/redirect-message-card.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/lib/stack-app.ts
|
|
2
2
|
import React, { use, useCallback, useMemo } from "react";
|
|
3
|
-
import { KnownError, StackAdminInterface, StackClientInterface, StackServerInterface } from "@stackframe/stack-shared";
|
|
3
|
+
import { KnownError, KnownErrors, StackAdminInterface, StackClientInterface, StackServerInterface } from "@stackframe/stack-shared";
|
|
4
4
|
import { getCookie, setOrDeleteCookie } from "./cookie";
|
|
5
5
|
import { StackAssertionError, throwErr } from "@stackframe/stack-shared/dist/utils/errors";
|
|
6
6
|
import { generateUuid } from "@stackframe/stack-shared/dist/utils/uuids";
|
|
@@ -9,11 +9,11 @@ import { suspendIfSsr } from "@stackframe/stack-shared/dist/utils/react";
|
|
|
9
9
|
import { Store } from "@stackframe/stack-shared/dist/utils/stores";
|
|
10
10
|
import { getProductionModeErrors } from "@stackframe/stack-shared/dist/interface/clientInterface";
|
|
11
11
|
import { isBrowserLike } from "@stackframe/stack-shared/dist/utils/env";
|
|
12
|
-
import { callOAuthCallback, signInWithOAuth } from "./auth";
|
|
12
|
+
import { addNewOAuthProviderOrScope, callOAuthCallback, signInWithOAuth } from "./auth";
|
|
13
13
|
import * as NextNavigationUnscrambled from "next/navigation";
|
|
14
14
|
import { constructRedirectUrl } from "../utils/url";
|
|
15
15
|
import { deepPlainEquals, filterUndefined, omit } from "@stackframe/stack-shared/dist/utils/objects";
|
|
16
|
-
import { resolved, runAsynchronously, wait } from "@stackframe/stack-shared/dist/utils/promises";
|
|
16
|
+
import { neverResolve, resolved, runAsynchronously, wait } from "@stackframe/stack-shared/dist/utils/promises";
|
|
17
17
|
import { AsyncCache } from "@stackframe/stack-shared/dist/utils/caches";
|
|
18
18
|
import { suspend } from "@stackframe/stack-shared/dist/utils/react";
|
|
19
19
|
import { scrambleDuringCompileTime } from "@stackframe/stack-shared/dist/utils/compile-time";
|
|
@@ -21,8 +21,9 @@ import { isReactServer } from "@stackframe/stack-sc";
|
|
|
21
21
|
import * as cookie from "cookie";
|
|
22
22
|
import { InternalSession } from "@stackframe/stack-shared/dist/sessions";
|
|
23
23
|
import { useTrigger } from "@stackframe/stack-shared/dist/hooks/use-trigger";
|
|
24
|
+
import { mergeScopeStrings } from "@stackframe/stack-shared/dist/utils/strings";
|
|
24
25
|
var NextNavigation = scrambleDuringCompileTime(NextNavigationUnscrambled);
|
|
25
|
-
var clientVersion = "js @stackframe/stack@2.4.
|
|
26
|
+
var clientVersion = "js @stackframe/stack@2.4.23";
|
|
26
27
|
function permissionDefinitionScopeToType(scope) {
|
|
27
28
|
return { "any-team": "team", "specific-team": "team", "global": "global" }[scope.type];
|
|
28
29
|
}
|
|
@@ -43,9 +44,22 @@ function getUrls(partial) {
|
|
|
43
44
|
magicLinkCallback: `${handler}/magic-link-callback`,
|
|
44
45
|
home: "/",
|
|
45
46
|
accountSettings: `${handler}/account-settings`,
|
|
47
|
+
error: `${handler}/error`,
|
|
46
48
|
...filterUndefined(partial)
|
|
47
49
|
};
|
|
48
50
|
}
|
|
51
|
+
async function _redirectTo(url, options) {
|
|
52
|
+
if (isReactServer) {
|
|
53
|
+
NextNavigation.redirect(url, options?.replace ? NextNavigation.RedirectType.replace : NextNavigation.RedirectType.push);
|
|
54
|
+
} else {
|
|
55
|
+
if (options?.replace) {
|
|
56
|
+
window.location.replace(url);
|
|
57
|
+
} else {
|
|
58
|
+
window.location.assign(url);
|
|
59
|
+
}
|
|
60
|
+
await wait(2e3);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
49
63
|
function getDefaultProjectId() {
|
|
50
64
|
return process.env.NEXT_PUBLIC_STACK_PROJECT_ID || throwErr(new Error("Welcome to Stack! 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."));
|
|
51
65
|
}
|
|
@@ -120,6 +134,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
120
134
|
}
|
|
121
135
|
this._tokenStoreInit = _options.tokenStore;
|
|
122
136
|
this._urlOptions = _options.urls ?? {};
|
|
137
|
+
this._oauthScopesOnSignIn = _options.oauthScopesOnSignIn ?? {};
|
|
123
138
|
if (_options.uniqueIdentifier) {
|
|
124
139
|
this._uniqueIdentifier = _options.uniqueIdentifier;
|
|
125
140
|
this._initUniqueIdentifier();
|
|
@@ -133,6 +148,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
133
148
|
_interface;
|
|
134
149
|
_tokenStoreInit;
|
|
135
150
|
_urlOptions;
|
|
151
|
+
_oauthScopesOnSignIn;
|
|
136
152
|
__DEMO_ENABLE_SLIGHT_FETCH_DELAY = false;
|
|
137
153
|
_currentUserCache = createCacheBySession(async (session) => {
|
|
138
154
|
if (this.__DEMO_ENABLE_SLIGHT_FETCH_DELAY) {
|
|
@@ -153,6 +169,64 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
153
169
|
_currentUserTeamsCache = createCacheBySession(async (session) => {
|
|
154
170
|
return await this._interface.listClientUserTeams(session);
|
|
155
171
|
});
|
|
172
|
+
_currentUserOAuthConnectionAccessTokensCache = createCacheBySession(
|
|
173
|
+
async (session, [accountId, scope]) => {
|
|
174
|
+
try {
|
|
175
|
+
return await this._interface.getAccessToken(accountId, scope || "", session);
|
|
176
|
+
} catch (err) {
|
|
177
|
+
if (!(err instanceof KnownErrors.OAuthConnectionDoesNotHaveRequiredScope || err instanceof KnownErrors.OAuthConnectionNotConnectedToUser)) {
|
|
178
|
+
throw err;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
_currentUserOAuthConnectionCache = createCacheBySession(
|
|
185
|
+
async (session, [connectionId, scope, redirect]) => {
|
|
186
|
+
const user = await this._currentUserCache.getOrWait([session], "write-only");
|
|
187
|
+
let hasConnection = true;
|
|
188
|
+
if (!user || !user.oauthProviders.find((p) => p === connectionId)) {
|
|
189
|
+
hasConnection = false;
|
|
190
|
+
}
|
|
191
|
+
const token = await this._currentUserOAuthConnectionAccessTokensCache.getOrWait([session, connectionId, scope || ""], "write-only");
|
|
192
|
+
if (!token) {
|
|
193
|
+
hasConnection = false;
|
|
194
|
+
}
|
|
195
|
+
if (!hasConnection && redirect) {
|
|
196
|
+
await addNewOAuthProviderOrScope(
|
|
197
|
+
this._interface,
|
|
198
|
+
{
|
|
199
|
+
provider: connectionId,
|
|
200
|
+
redirectUrl: this.urls.oauthCallback,
|
|
201
|
+
errorRedirectUrl: this.urls.error,
|
|
202
|
+
providerScope: mergeScopeStrings(scope || "", (this._oauthScopesOnSignIn[connectionId] ?? []).join(" "))
|
|
203
|
+
},
|
|
204
|
+
this._getSession()
|
|
205
|
+
);
|
|
206
|
+
return await neverResolve();
|
|
207
|
+
} else if (!hasConnection) {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
const app = this;
|
|
211
|
+
return {
|
|
212
|
+
id: connectionId,
|
|
213
|
+
async getAccessToken() {
|
|
214
|
+
const result = await app._currentUserOAuthConnectionAccessTokensCache.getOrWait([session, connectionId, scope || ""], "write-only");
|
|
215
|
+
if (!result) {
|
|
216
|
+
throw new StackAssertionError("No access token available");
|
|
217
|
+
}
|
|
218
|
+
return result;
|
|
219
|
+
},
|
|
220
|
+
useAccessToken() {
|
|
221
|
+
const result = useAsyncCache(app._currentUserOAuthConnectionAccessTokensCache, [session, connectionId, scope || ""], "oauthAccount.useAccessToken()");
|
|
222
|
+
if (!result) {
|
|
223
|
+
throw new StackAssertionError("No access token available");
|
|
224
|
+
}
|
|
225
|
+
return result;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
);
|
|
156
230
|
_initUniqueIdentifier() {
|
|
157
231
|
if (!this._uniqueIdentifier) {
|
|
158
232
|
throw new StackAssertionError("Unique identifier not initialized");
|
|
@@ -389,6 +463,14 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
389
463
|
}
|
|
390
464
|
_userFromJson(json) {
|
|
391
465
|
const app = this;
|
|
466
|
+
async function getConnection(id, options) {
|
|
467
|
+
const scopeString = options?.scopes?.join(" ");
|
|
468
|
+
return await app._currentUserOAuthConnectionCache.getOrWait([app._getSession(), id, scopeString || "", options?.or === "redirect"], "write-only");
|
|
469
|
+
}
|
|
470
|
+
function useConnection(id, options) {
|
|
471
|
+
const scopeString = options?.scopes?.join(" ");
|
|
472
|
+
return useAsyncCache(app._currentUserOAuthConnectionCache, [app._useSession(), id, scopeString || "", options?.or === "redirect"], "user.useConnection()");
|
|
473
|
+
}
|
|
392
474
|
return {
|
|
393
475
|
projectId: json.projectId,
|
|
394
476
|
id: json.id,
|
|
@@ -402,6 +484,8 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
402
484
|
hasPassword: json.hasPassword,
|
|
403
485
|
authWithEmail: json.authWithEmail,
|
|
404
486
|
oauthProviders: json.oauthProviders,
|
|
487
|
+
getConnection,
|
|
488
|
+
useConnection,
|
|
405
489
|
async getSelectedTeam() {
|
|
406
490
|
return await this.getTeam(json.selectedTeamId || "");
|
|
407
491
|
},
|
|
@@ -471,12 +555,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
471
555
|
displayName: json.displayName
|
|
472
556
|
};
|
|
473
557
|
}
|
|
474
|
-
|
|
475
|
-
if (json === null)
|
|
476
|
-
return null;
|
|
558
|
+
_authFromJson(session) {
|
|
477
559
|
const app = this;
|
|
478
|
-
|
|
479
|
-
...this._userFromJson(json),
|
|
560
|
+
return {
|
|
480
561
|
_internalSession: session,
|
|
481
562
|
currentSession: {
|
|
482
563
|
async getTokens() {
|
|
@@ -487,15 +568,25 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
487
568
|
};
|
|
488
569
|
}
|
|
489
570
|
},
|
|
571
|
+
async getAuthHeaders() {
|
|
572
|
+
return {
|
|
573
|
+
"x-stack-auth": JSON.stringify(await this.getAuthJson())
|
|
574
|
+
};
|
|
575
|
+
},
|
|
576
|
+
async getAuthJson() {
|
|
577
|
+
const tokens = await this.currentSession.getTokens();
|
|
578
|
+
return tokens;
|
|
579
|
+
},
|
|
580
|
+
signOut() {
|
|
581
|
+
return app._signOut(session);
|
|
582
|
+
},
|
|
583
|
+
// TODO these should not actually be on Auth, instead on User
|
|
490
584
|
async updateSelectedTeam(team) {
|
|
491
585
|
await app._updateUser({ selectedTeamId: team?.id ?? null }, session);
|
|
492
586
|
},
|
|
493
587
|
update(update) {
|
|
494
588
|
return app._updateUser(update, session);
|
|
495
589
|
},
|
|
496
|
-
signOut() {
|
|
497
|
-
return app._signOut(session);
|
|
498
|
-
},
|
|
499
590
|
sendVerificationEmail() {
|
|
500
591
|
return app._sendVerificationEmail(session);
|
|
501
592
|
},
|
|
@@ -503,6 +594,15 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
503
594
|
return app._updatePassword(options, session);
|
|
504
595
|
}
|
|
505
596
|
};
|
|
597
|
+
}
|
|
598
|
+
_currentUserFromJson(json, session) {
|
|
599
|
+
if (json === null)
|
|
600
|
+
return null;
|
|
601
|
+
const app = this;
|
|
602
|
+
const currentUser = {
|
|
603
|
+
...this._userFromJson(json),
|
|
604
|
+
...this._authFromJson(session)
|
|
605
|
+
};
|
|
506
606
|
if (this._isInternalProject()) {
|
|
507
607
|
const internalUser = {
|
|
508
608
|
...currentUser,
|
|
@@ -573,33 +673,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
573
673
|
get urls() {
|
|
574
674
|
return getUrls(this._urlOptions);
|
|
575
675
|
}
|
|
576
|
-
async getCrossOriginHeaders() {
|
|
577
|
-
return {
|
|
578
|
-
"x-stack-auth": JSON.stringify(await this.getCrossOriginTokenObject())
|
|
579
|
-
};
|
|
580
|
-
}
|
|
581
|
-
async getCrossOriginTokenObject() {
|
|
582
|
-
const user = await this.getUser();
|
|
583
|
-
if (!user)
|
|
584
|
-
return { accessToken: null, refreshToken: null };
|
|
585
|
-
const tokens = await user.currentSession.getTokens();
|
|
586
|
-
return tokens;
|
|
587
|
-
}
|
|
588
676
|
async _redirectTo(handlerName, options) {
|
|
589
677
|
const url = this.urls[handlerName];
|
|
590
678
|
if (!url) {
|
|
591
679
|
throw new Error(`No URL for handler name ${handlerName}`);
|
|
592
680
|
}
|
|
593
|
-
|
|
594
|
-
NextNavigation.redirect(url, options?.replace ? NextNavigation.RedirectType.replace : NextNavigation.RedirectType.push);
|
|
595
|
-
} else {
|
|
596
|
-
if (options?.replace) {
|
|
597
|
-
window.location.replace(url);
|
|
598
|
-
} else {
|
|
599
|
-
window.location.assign(url);
|
|
600
|
-
}
|
|
601
|
-
await wait(2e3);
|
|
602
|
-
}
|
|
681
|
+
await _redirectTo(url, options);
|
|
603
682
|
}
|
|
604
683
|
async redirectToSignIn() {
|
|
605
684
|
return await this._redirectTo("signIn");
|
|
@@ -640,6 +719,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
640
719
|
async redirectToAccountSettings() {
|
|
641
720
|
return await this._redirectTo("accountSettings");
|
|
642
721
|
}
|
|
722
|
+
async redirectToError() {
|
|
723
|
+
return await this._redirectTo("error");
|
|
724
|
+
}
|
|
643
725
|
async sendForgotPasswordEmail(email) {
|
|
644
726
|
const redirectUrl = constructRedirectUrl(this.urls.passwordReset);
|
|
645
727
|
const error = await this._interface.sendForgotPasswordEmail(email, redirectUrl);
|
|
@@ -719,7 +801,15 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
719
801
|
}
|
|
720
802
|
async signInWithOAuth(provider) {
|
|
721
803
|
this._ensurePersistentTokenStore();
|
|
722
|
-
await signInWithOAuth(
|
|
804
|
+
await signInWithOAuth(
|
|
805
|
+
this._interface,
|
|
806
|
+
{
|
|
807
|
+
provider,
|
|
808
|
+
redirectUrl: this.urls.oauthCallback,
|
|
809
|
+
errorRedirectUrl: this.urls.error,
|
|
810
|
+
providerScope: this._oauthScopesOnSignIn[provider]?.join(" ")
|
|
811
|
+
}
|
|
812
|
+
);
|
|
723
813
|
}
|
|
724
814
|
async signInWithCredential(options) {
|
|
725
815
|
this._ensurePersistentTokenStore();
|
|
@@ -766,7 +856,10 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
766
856
|
const result = await callOAuthCallback(this._interface, this.urls.oauthCallback);
|
|
767
857
|
if (result) {
|
|
768
858
|
await this._signInToAccountWithTokens(result);
|
|
769
|
-
if (result.
|
|
859
|
+
if (result.afterCallbackRedirectUrl) {
|
|
860
|
+
await _redirectTo(result.afterCallbackRedirectUrl, { replace: true });
|
|
861
|
+
return true;
|
|
862
|
+
} else if (result.newUser) {
|
|
770
863
|
await this.redirectToAfterSignUp({ replace: true });
|
|
771
864
|
return true;
|
|
772
865
|
} else {
|
|
@@ -846,6 +939,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
846
939
|
return res;
|
|
847
940
|
}
|
|
848
941
|
async _refreshUser(session) {
|
|
942
|
+
await this._refreshSession(session);
|
|
943
|
+
}
|
|
944
|
+
async _refreshSession(session) {
|
|
849
945
|
await this._currentUserCache.refresh([session]);
|
|
850
946
|
}
|
|
851
947
|
async _refreshUsers() {
|
|
@@ -889,6 +985,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
889
985
|
publishableClientKey: this._interface.options.publishableClientKey,
|
|
890
986
|
tokenStore: this._tokenStoreInit,
|
|
891
987
|
urls: this._urlOptions,
|
|
988
|
+
oauthScopesOnSignIn: this._oauthScopesOnSignIn,
|
|
892
989
|
uniqueIdentifier: this._getUniqueIdentifier()
|
|
893
990
|
};
|
|
894
991
|
},
|
|
@@ -930,7 +1027,8 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
930
1027
|
super("interface" in options ? {
|
|
931
1028
|
interface: options.interface,
|
|
932
1029
|
tokenStore: options.tokenStore,
|
|
933
|
-
urls: options.urls
|
|
1030
|
+
urls: options.urls,
|
|
1031
|
+
oauthScopesOnSignIn: options.oauthScopesOnSignIn
|
|
934
1032
|
} : {
|
|
935
1033
|
interface: new StackServerInterface({
|
|
936
1034
|
baseUrl: options.baseUrl ?? getDefaultBaseUrl(),
|
|
@@ -940,7 +1038,8 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
940
1038
|
secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey()
|
|
941
1039
|
}),
|
|
942
1040
|
tokenStore: options.tokenStore,
|
|
943
|
-
urls: options.urls ?? {}
|
|
1041
|
+
urls: options.urls ?? {},
|
|
1042
|
+
oauthScopesOnSignIn: options.oauthScopesOnSignIn ?? {}
|
|
944
1043
|
});
|
|
945
1044
|
}
|
|
946
1045
|
_serverUserFromJson(json) {
|
|
@@ -1036,40 +1135,14 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1036
1135
|
const nonCurrentServerUser = this._serverUserFromJson(json);
|
|
1037
1136
|
const currentUser = {
|
|
1038
1137
|
...nonCurrentServerUser,
|
|
1039
|
-
|
|
1040
|
-
currentSession: {
|
|
1041
|
-
async getTokens() {
|
|
1042
|
-
const tokens = await session.getPotentiallyExpiredTokens();
|
|
1043
|
-
return {
|
|
1044
|
-
accessToken: tokens?.accessToken.token ?? null,
|
|
1045
|
-
refreshToken: tokens?.refreshToken?.token ?? null
|
|
1046
|
-
};
|
|
1047
|
-
}
|
|
1048
|
-
},
|
|
1138
|
+
...this._authFromJson(session),
|
|
1049
1139
|
async delete() {
|
|
1050
1140
|
const res = await nonCurrentServerUser.delete();
|
|
1051
1141
|
await app._refreshUser(session);
|
|
1052
1142
|
return res;
|
|
1053
1143
|
},
|
|
1054
|
-
async updateSelectedTeam(team) {
|
|
1055
|
-
await this.update({ selectedTeamId: team?.id ?? null });
|
|
1056
|
-
},
|
|
1057
|
-
async update(update) {
|
|
1058
|
-
const res = await nonCurrentServerUser.update(update);
|
|
1059
|
-
await app._refreshUser(session);
|
|
1060
|
-
return res;
|
|
1061
|
-
},
|
|
1062
|
-
signOut() {
|
|
1063
|
-
return app._signOut(session);
|
|
1064
|
-
},
|
|
1065
1144
|
getClientUser() {
|
|
1066
1145
|
return app._currentUserFromJson(json, session);
|
|
1067
|
-
},
|
|
1068
|
-
sendVerificationEmail() {
|
|
1069
|
-
return app._sendVerificationEmail(session);
|
|
1070
|
-
},
|
|
1071
|
-
updatePassword(options) {
|
|
1072
|
-
return app._updatePassword(options, session);
|
|
1073
1146
|
}
|
|
1074
1147
|
};
|
|
1075
1148
|
if (this._isInternalProject()) {
|
|
@@ -1244,7 +1317,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1244
1317
|
return teams.find((t) => t.id === teamId) ?? null;
|
|
1245
1318
|
}, [teams, teamId]);
|
|
1246
1319
|
}
|
|
1247
|
-
async
|
|
1320
|
+
async _refreshSession(session) {
|
|
1248
1321
|
await Promise.all([
|
|
1249
1322
|
super._refreshUser(session),
|
|
1250
1323
|
this._currentServerUserCache.refresh([session])
|
|
@@ -1293,7 +1366,8 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
|
|
|
1293
1366
|
}
|
|
1294
1367
|
}),
|
|
1295
1368
|
tokenStore: options.tokenStore,
|
|
1296
|
-
urls: options.urls
|
|
1369
|
+
urls: options.urls,
|
|
1370
|
+
oauthScopesOnSignIn: options.oauthScopesOnSignIn
|
|
1297
1371
|
});
|
|
1298
1372
|
}
|
|
1299
1373
|
_createApiKeySetBaseFromJson(data) {
|