@stackframe/stack 2.4.8 → 2.4.9
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/dist/components/oauth-button.d.mts +1 -1
- package/dist/components/oauth-button.d.ts +1 -1
- package/dist/components/oauth-button.js +3 -4
- package/dist/components/oauth-button.js.map +1 -1
- package/dist/components/oauth-group.d.mts +1 -1
- package/dist/components/oauth-group.d.ts +1 -1
- package/dist/components/oauth-group.js.map +1 -1
- package/dist/components-page/auth-page.js +1 -1
- package/dist/components-page/auth-page.js.map +1 -1
- package/dist/esm/components/oauth-button.js +3 -4
- package/dist/esm/components/oauth-button.js.map +1 -1
- package/dist/esm/components/oauth-group.js.map +1 -1
- package/dist/esm/components-page/auth-page.js +1 -1
- package/dist/esm/components-page/auth-page.js.map +1 -1
- package/dist/esm/lib/cookie.js +1 -1
- package/dist/esm/lib/cookie.js.map +1 -1
- package/dist/esm/lib/stack-app.js +104 -76
- package/dist/esm/lib/stack-app.js.map +1 -1
- package/dist/lib/cookie.js +4 -4
- package/dist/lib/cookie.js.map +1 -1
- package/dist/lib/stack-app.d.mts +4 -3
- package/dist/lib/stack-app.d.ts +4 -3
- package/dist/lib/stack-app.js +104 -76
- package/dist/lib/stack-app.js.map +1 -1
- package/package.json +5 -3
|
@@ -10,13 +10,17 @@ import { AsyncStore } from "@stackframe/stack-shared/dist/utils/stores";
|
|
|
10
10
|
import { getProductionModeErrors } from "@stackframe/stack-shared/dist/interface/clientInterface";
|
|
11
11
|
import { isClient } from "../utils/next";
|
|
12
12
|
import { callOAuthCallback, signInWithOAuth } from "./auth";
|
|
13
|
-
import * as
|
|
13
|
+
import * as NextNavigationUnscrambled from "next/navigation";
|
|
14
14
|
import { constructRedirectUrl } from "../utils/url";
|
|
15
15
|
import { filterUndefined, omit } from "@stackframe/stack-shared/dist/utils/objects";
|
|
16
16
|
import { 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";
|
|
20
|
+
import { isReactServer } from "@stackframe/stack-sc";
|
|
21
|
+
import * as cookie from "cookie";
|
|
22
|
+
var NextNavigation = scrambleDuringCompileTime(NextNavigationUnscrambled);
|
|
23
|
+
var clientVersion = "js @stackframe/stack@2.4.9";
|
|
20
24
|
function permissionDefinitionScopeToType(scope) {
|
|
21
25
|
return { "any-team": "team", "specific-team": "team", "global": "global" }[scope.type];
|
|
22
26
|
}
|
|
@@ -57,14 +61,11 @@ function getDefaultBaseUrl() {
|
|
|
57
61
|
}
|
|
58
62
|
var defaultBaseUrl = "https://app.stack-auth.com";
|
|
59
63
|
function createEmptyTokenStore() {
|
|
60
|
-
|
|
61
|
-
store.set({
|
|
64
|
+
return new AsyncStore({
|
|
62
65
|
refreshToken: null,
|
|
63
66
|
accessToken: null
|
|
64
67
|
});
|
|
65
|
-
return store;
|
|
66
68
|
}
|
|
67
|
-
var memoryTokenStore = createEmptyTokenStore();
|
|
68
69
|
var cookieTokenStore = null;
|
|
69
70
|
var cookieTokenStoreInitializer = () => {
|
|
70
71
|
if (!isClient()) {
|
|
@@ -97,33 +98,6 @@ var cookieTokenStoreInitializer = () => {
|
|
|
97
98
|
}
|
|
98
99
|
return cookieTokenStore;
|
|
99
100
|
};
|
|
100
|
-
var tokenStoreInitializers = /* @__PURE__ */ new Map([
|
|
101
|
-
["cookie", cookieTokenStoreInitializer],
|
|
102
|
-
["nextjs-cookie", () => {
|
|
103
|
-
if (isClient()) {
|
|
104
|
-
return cookieTokenStoreInitializer();
|
|
105
|
-
} else {
|
|
106
|
-
const store = new AsyncStore();
|
|
107
|
-
store.set({
|
|
108
|
-
refreshToken: getCookie("stack-refresh"),
|
|
109
|
-
accessToken: getCookie("stack-access")
|
|
110
|
-
});
|
|
111
|
-
store.onChange((value) => {
|
|
112
|
-
try {
|
|
113
|
-
setOrDeleteCookie("stack-refresh", value.refreshToken, { maxAge: 60 * 60 * 24 * 365 });
|
|
114
|
-
setOrDeleteCookie("stack-access", value.accessToken, { maxAge: 60 * 60 * 24 });
|
|
115
|
-
} catch (e) {
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
return store;
|
|
119
|
-
}
|
|
120
|
-
}],
|
|
121
|
-
["memory", () => memoryTokenStore],
|
|
122
|
-
[null, () => createEmptyTokenStore()]
|
|
123
|
-
]);
|
|
124
|
-
function getTokenStore(tokenStoreOptions) {
|
|
125
|
-
return (tokenStoreInitializers.get(tokenStoreOptions) ?? throwErr(`Invalid token store ${tokenStoreOptions}`))();
|
|
126
|
-
}
|
|
127
101
|
var loadingSentinel = Symbol("stackAppCacheLoadingSentinel");
|
|
128
102
|
function useCache(cache, dependencies, caller) {
|
|
129
103
|
suspendIfSsr(caller);
|
|
@@ -167,7 +141,7 @@ var createCacheByTokenStore = (fetcher) => {
|
|
|
167
141
|
var _StackClientAppImpl = class __StackClientAppImpl {
|
|
168
142
|
_uniqueIdentifier;
|
|
169
143
|
_interface;
|
|
170
|
-
|
|
144
|
+
_tokenStoreInit;
|
|
171
145
|
_urlOptions;
|
|
172
146
|
__DEMO_ENABLE_SLIGHT_FETCH_DELAY = false;
|
|
173
147
|
_currentUserCache = createCacheByTokenStore(async (tokenStore) => {
|
|
@@ -200,7 +174,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
200
174
|
publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey()
|
|
201
175
|
});
|
|
202
176
|
}
|
|
203
|
-
this.
|
|
177
|
+
this._tokenStoreInit = options.tokenStore;
|
|
204
178
|
this._urlOptions = options.urls ?? {};
|
|
205
179
|
this._uniqueIdentifier = options.uniqueIdentifier ?? generateUuid();
|
|
206
180
|
if (allClientApps.has(this._uniqueIdentifier)) {
|
|
@@ -208,19 +182,69 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
208
182
|
}
|
|
209
183
|
allClientApps.set(this._uniqueIdentifier, [options.checkString ?? "default check string", this]);
|
|
210
184
|
}
|
|
211
|
-
|
|
212
|
-
|
|
185
|
+
_memoryTokenStore = createEmptyTokenStore();
|
|
186
|
+
_requestTokenStores = /* @__PURE__ */ new Map();
|
|
187
|
+
_getTokenStore(overrideTokenStoreInit) {
|
|
188
|
+
const tokenStoreInit = overrideTokenStoreInit === void 0 ? this._tokenStoreInit : overrideTokenStoreInit;
|
|
189
|
+
switch (tokenStoreInit) {
|
|
190
|
+
case "cookie": {
|
|
191
|
+
return cookieTokenStoreInitializer();
|
|
192
|
+
}
|
|
193
|
+
case "nextjs-cookie": {
|
|
194
|
+
if (isClient()) {
|
|
195
|
+
return cookieTokenStoreInitializer();
|
|
196
|
+
} else {
|
|
197
|
+
const store = new AsyncStore();
|
|
198
|
+
store.set({
|
|
199
|
+
refreshToken: getCookie("stack-refresh"),
|
|
200
|
+
accessToken: getCookie("stack-access")
|
|
201
|
+
});
|
|
202
|
+
store.onChange((value) => {
|
|
203
|
+
try {
|
|
204
|
+
setOrDeleteCookie("stack-refresh", value.refreshToken, { maxAge: 60 * 60 * 24 * 365 });
|
|
205
|
+
setOrDeleteCookie("stack-access", value.accessToken, { maxAge: 60 * 60 * 24 });
|
|
206
|
+
} catch (e) {
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
return store;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
case "memory": {
|
|
213
|
+
return this._memoryTokenStore;
|
|
214
|
+
}
|
|
215
|
+
case null: {
|
|
216
|
+
return createEmptyTokenStore();
|
|
217
|
+
}
|
|
218
|
+
default: {
|
|
219
|
+
if (tokenStoreInit && typeof tokenStoreInit === "object" && "headers" in tokenStoreInit) {
|
|
220
|
+
if (this._requestTokenStores.has(tokenStoreInit))
|
|
221
|
+
return this._requestTokenStores.get(tokenStoreInit);
|
|
222
|
+
const cookieHeader = tokenStoreInit.headers.get("cookie");
|
|
223
|
+
const parsed = cookie.parse(cookieHeader || "");
|
|
224
|
+
const res = new AsyncStore({
|
|
225
|
+
refreshToken: parsed["stack-refresh"] || null,
|
|
226
|
+
accessToken: parsed["stack-access"] || null
|
|
227
|
+
});
|
|
228
|
+
this._requestTokenStores.set(tokenStoreInit, res);
|
|
229
|
+
return res;
|
|
230
|
+
}
|
|
231
|
+
throw new Error(`Invalid token store ${tokenStoreInit}`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
_hasPersistentTokenStore(overrideTokenStoreInit) {
|
|
236
|
+
return (overrideTokenStoreInit !== void 0 ? overrideTokenStoreInit : this._tokenStoreInit) !== null;
|
|
213
237
|
}
|
|
214
|
-
_ensurePersistentTokenStore() {
|
|
215
|
-
if (!this.
|
|
216
|
-
throw new Error("Cannot call this function on a Stack app without a persistent token store. Make sure the tokenStore option is set to a non-null value when initializing Stack.");
|
|
238
|
+
_ensurePersistentTokenStore(overrideTokenStoreInit) {
|
|
239
|
+
if (!this._hasPersistentTokenStore(overrideTokenStoreInit)) {
|
|
240
|
+
throw new Error("Cannot call this function on a Stack app without a persistent token store. Make sure the tokenStore option on the constructor is set to a non-null value when initializing Stack.\n\nStack uses token stores to access access tokens of the current user. For example, on web frontends it is commonly the string value 'cookies' for cookie storage.");
|
|
217
241
|
}
|
|
218
242
|
}
|
|
219
|
-
|
|
243
|
+
_isInternalProject() {
|
|
220
244
|
return this.projectId === "internal";
|
|
221
245
|
}
|
|
222
246
|
_ensureInternalProject() {
|
|
223
|
-
if (!this.
|
|
247
|
+
if (!this._isInternalProject()) {
|
|
224
248
|
throw new Error("Cannot call this function on a Stack app with a project ID other than 'internal'.");
|
|
225
249
|
}
|
|
226
250
|
}
|
|
@@ -287,24 +311,24 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
287
311
|
});
|
|
288
312
|
},
|
|
289
313
|
async listTeams() {
|
|
290
|
-
const teams = await app._currentUserTeamsCache.getOrWait([
|
|
314
|
+
const teams = await app._currentUserTeamsCache.getOrWait([app._getTokenStore()], "write-only");
|
|
291
315
|
return teams.map((json2) => app._teamFromJson(json2));
|
|
292
316
|
},
|
|
293
317
|
useTeams() {
|
|
294
|
-
const teams = useCache(app._currentUserTeamsCache, [
|
|
318
|
+
const teams = useCache(app._currentUserTeamsCache, [app._getTokenStore()], "user.useTeams()");
|
|
295
319
|
return useMemo(() => teams.map((json2) => app._teamFromJson(json2)), [teams]);
|
|
296
320
|
},
|
|
297
321
|
onTeamsChange(callback) {
|
|
298
|
-
return app._currentUserTeamsCache.onChange([
|
|
322
|
+
return app._currentUserTeamsCache.onChange([app._getTokenStore()], (value, oldValue) => {
|
|
299
323
|
callback(value.map((json2) => app._teamFromJson(json2)), oldValue?.map((json2) => app._teamFromJson(json2)));
|
|
300
324
|
});
|
|
301
325
|
},
|
|
302
326
|
async listPermissions(scope, options) {
|
|
303
|
-
const permissions = await app._currentUserPermissionsCache.getOrWait([
|
|
327
|
+
const permissions = await app._currentUserPermissionsCache.getOrWait([app._getTokenStore(), scope.id, "team", !!options?.direct], "write-only");
|
|
304
328
|
return permissions.map((json2) => app._permissionFromJson(json2));
|
|
305
329
|
},
|
|
306
330
|
usePermissions(scope, options) {
|
|
307
|
-
const permissions = useCache(app._currentUserPermissionsCache, [
|
|
331
|
+
const permissions = useCache(app._currentUserPermissionsCache, [app._getTokenStore(), scope.id, "team", !!options?.direct], "user.usePermissions()");
|
|
308
332
|
return useMemo(() => permissions.map((json2) => app._permissionFromJson(json2)), [permissions]);
|
|
309
333
|
},
|
|
310
334
|
usePermission(scope, permissionId) {
|
|
@@ -355,7 +379,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
355
379
|
return app._updatePassword(options, tokenStore);
|
|
356
380
|
}
|
|
357
381
|
};
|
|
358
|
-
if (this.
|
|
382
|
+
if (this._isInternalProject()) {
|
|
359
383
|
const internalUser = {
|
|
360
384
|
...currentUser,
|
|
361
385
|
createProject(newProject) {
|
|
@@ -430,12 +454,16 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
430
454
|
if (!url) {
|
|
431
455
|
throw new Error(`No URL for handler name ${handlerName}`);
|
|
432
456
|
}
|
|
433
|
-
if (
|
|
434
|
-
|
|
457
|
+
if (isReactServer) {
|
|
458
|
+
NextNavigation.redirect(url, options?.replace ? NextNavigation.RedirectType.replace : NextNavigation.RedirectType.push);
|
|
435
459
|
} else {
|
|
436
|
-
|
|
460
|
+
if (options?.replace) {
|
|
461
|
+
window.location.replace(url);
|
|
462
|
+
} else {
|
|
463
|
+
window.location.assign(url);
|
|
464
|
+
}
|
|
465
|
+
await wait(2e3);
|
|
437
466
|
}
|
|
438
|
-
return await wait(2e3);
|
|
439
467
|
}
|
|
440
468
|
async redirectToSignIn() {
|
|
441
469
|
return await this._redirectTo("signIn");
|
|
@@ -497,14 +525,14 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
497
525
|
return await this._interface.verifyEmail(code);
|
|
498
526
|
}
|
|
499
527
|
async getUser(options) {
|
|
500
|
-
this._ensurePersistentTokenStore();
|
|
501
|
-
const tokenStore =
|
|
528
|
+
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
529
|
+
const tokenStore = this._getTokenStore(options?.tokenStore);
|
|
502
530
|
const userJson = await this._currentUserCache.getOrWait([tokenStore], "write-only");
|
|
503
531
|
if (userJson === null) {
|
|
504
532
|
switch (options?.or) {
|
|
505
533
|
case "redirect": {
|
|
506
|
-
|
|
507
|
-
|
|
534
|
+
await this.redirectToSignIn();
|
|
535
|
+
break;
|
|
508
536
|
}
|
|
509
537
|
case "throw": {
|
|
510
538
|
throw new Error("User is not signed in but getUser was called with { or: 'throw' }");
|
|
@@ -517,9 +545,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
517
545
|
return this._currentUserFromJson(userJson, tokenStore);
|
|
518
546
|
}
|
|
519
547
|
useUser(options) {
|
|
520
|
-
this._ensurePersistentTokenStore();
|
|
548
|
+
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
521
549
|
const router = NextNavigation.useRouter();
|
|
522
|
-
const tokenStore =
|
|
550
|
+
const tokenStore = this._getTokenStore(options?.tokenStore);
|
|
523
551
|
const userJson = useCache(this._currentUserCache, [tokenStore], "useUser()");
|
|
524
552
|
if (userJson === null) {
|
|
525
553
|
switch (options?.or) {
|
|
@@ -542,7 +570,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
542
570
|
}
|
|
543
571
|
onUserChange(callback) {
|
|
544
572
|
this._ensurePersistentTokenStore();
|
|
545
|
-
const tokenStore =
|
|
573
|
+
const tokenStore = this._getTokenStore();
|
|
546
574
|
return this._currentUserCache.onChange([tokenStore], (userJson) => {
|
|
547
575
|
callback(this._currentUserFromJson(userJson, tokenStore));
|
|
548
576
|
});
|
|
@@ -558,7 +586,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
558
586
|
}
|
|
559
587
|
async signInWithCredential(options) {
|
|
560
588
|
this._ensurePersistentTokenStore();
|
|
561
|
-
const tokenStore =
|
|
589
|
+
const tokenStore = this._getTokenStore();
|
|
562
590
|
const errorCode = await this._interface.signInWithCredential(options.email, options.password, tokenStore);
|
|
563
591
|
if (!errorCode) {
|
|
564
592
|
await this.redirectToAfterSignIn({ replace: true });
|
|
@@ -567,7 +595,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
567
595
|
}
|
|
568
596
|
async signUpWithCredential(options) {
|
|
569
597
|
this._ensurePersistentTokenStore();
|
|
570
|
-
const tokenStore =
|
|
598
|
+
const tokenStore = this._getTokenStore();
|
|
571
599
|
const emailVerificationRedirectUrl = constructRedirectUrl(this.urls.emailVerification);
|
|
572
600
|
const errorCode = await this._interface.signUpWithCredential(
|
|
573
601
|
options.email,
|
|
@@ -582,7 +610,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
582
610
|
}
|
|
583
611
|
async signInWithMagicLink(code) {
|
|
584
612
|
this._ensurePersistentTokenStore();
|
|
585
|
-
const tokenStore =
|
|
613
|
+
const tokenStore = this._getTokenStore();
|
|
586
614
|
const result = await this._interface.signInWithMagicLink(code, tokenStore);
|
|
587
615
|
if (result instanceof KnownError) {
|
|
588
616
|
return result;
|
|
@@ -595,7 +623,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
595
623
|
}
|
|
596
624
|
async callOAuthCallback() {
|
|
597
625
|
this._ensurePersistentTokenStore();
|
|
598
|
-
const tokenStore =
|
|
626
|
+
const tokenStore = this._getTokenStore();
|
|
599
627
|
const result = await callOAuthCallback(this._interface, tokenStore, this.urls.oauthCallback);
|
|
600
628
|
if (result) {
|
|
601
629
|
if (result.newUser) {
|
|
@@ -636,7 +664,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
636
664
|
}
|
|
637
665
|
async _listOwnedProjects() {
|
|
638
666
|
this._ensureInternalProject();
|
|
639
|
-
const tokenStore =
|
|
667
|
+
const tokenStore = this._getTokenStore();
|
|
640
668
|
const json = await this._ownedProjectsCache.getOrWait([tokenStore], "write-only");
|
|
641
669
|
return json.map((j) => this._projectAdminFromJson(
|
|
642
670
|
j,
|
|
@@ -646,7 +674,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
646
674
|
}
|
|
647
675
|
_useOwnedProjects() {
|
|
648
676
|
this._ensureInternalProject();
|
|
649
|
-
const tokenStore =
|
|
677
|
+
const tokenStore = this._getTokenStore();
|
|
650
678
|
const json = useCache(this._ownedProjectsCache, [tokenStore], "useOwnedProjects()");
|
|
651
679
|
return useMemo(() => json.map((j) => this._projectAdminFromJson(
|
|
652
680
|
j,
|
|
@@ -656,7 +684,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
656
684
|
}
|
|
657
685
|
_onOwnedProjectsChange(callback) {
|
|
658
686
|
this._ensureInternalProject();
|
|
659
|
-
const tokenStore =
|
|
687
|
+
const tokenStore = this._getTokenStore();
|
|
660
688
|
return this._ownedProjectsCache.onChange([tokenStore], (projects) => {
|
|
661
689
|
callback(projects.map((j) => this._projectAdminFromJson(
|
|
662
690
|
j,
|
|
@@ -667,7 +695,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
667
695
|
}
|
|
668
696
|
async _createProject(newProject) {
|
|
669
697
|
this._ensureInternalProject();
|
|
670
|
-
const tokenStore =
|
|
698
|
+
const tokenStore = this._getTokenStore();
|
|
671
699
|
const json = await this._interface.createProject(newProject, tokenStore);
|
|
672
700
|
const res = this._projectAdminFromJson(
|
|
673
701
|
json,
|
|
@@ -719,13 +747,13 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
719
747
|
baseUrl: this._interface.options.baseUrl,
|
|
720
748
|
projectId: this.projectId,
|
|
721
749
|
publishableClientKey: this._interface.options.publishableClientKey,
|
|
722
|
-
tokenStore: this.
|
|
750
|
+
tokenStore: this._tokenStoreInit,
|
|
723
751
|
urls: this._urlOptions,
|
|
724
752
|
uniqueIdentifier: this._uniqueIdentifier
|
|
725
753
|
};
|
|
726
754
|
},
|
|
727
755
|
setCurrentUser: (userJsonPromise) => {
|
|
728
|
-
runAsynchronously(this._currentUserCache.forceSetCachedValueAsync([
|
|
756
|
+
runAsynchronously(this._currentUserCache.forceSetCachedValueAsync([this._getTokenStore()], userJsonPromise));
|
|
729
757
|
}
|
|
730
758
|
};
|
|
731
759
|
}
|
|
@@ -821,15 +849,15 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
821
849
|
});
|
|
822
850
|
},
|
|
823
851
|
async listTeams() {
|
|
824
|
-
const teams = await app._serverTeamsCache.getOrWait([
|
|
852
|
+
const teams = await app._serverTeamsCache.getOrWait([app._getTokenStore()], "write-only");
|
|
825
853
|
return teams.map((json2) => app._serverTeamFromJson(json2));
|
|
826
854
|
},
|
|
827
855
|
useTeams() {
|
|
828
|
-
const teams = useCache(app._serverTeamsCache, [
|
|
856
|
+
const teams = useCache(app._serverTeamsCache, [app._getTokenStore()], "user.useTeams()");
|
|
829
857
|
return useMemo(() => teams.map((json2) => app._serverTeamFromJson(json2)), [teams]);
|
|
830
858
|
},
|
|
831
859
|
onTeamsChange(callback) {
|
|
832
|
-
return app._serverTeamsCache.onChange([
|
|
860
|
+
return app._serverTeamsCache.onChange([app._getTokenStore()], (value, oldValue) => {
|
|
833
861
|
callback(value.map((json2) => app._serverTeamFromJson(json2)), oldValue?.map((json2) => app._serverTeamFromJson(json2)));
|
|
834
862
|
});
|
|
835
863
|
},
|
|
@@ -892,7 +920,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
892
920
|
return app._updatePassword(options, tokenStore);
|
|
893
921
|
}
|
|
894
922
|
};
|
|
895
|
-
if (this.
|
|
923
|
+
if (this._isInternalProject()) {
|
|
896
924
|
const internalUser = {
|
|
897
925
|
...currentUser,
|
|
898
926
|
createProject(newProject) {
|
|
@@ -971,7 +999,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
971
999
|
}
|
|
972
1000
|
async getServerUser() {
|
|
973
1001
|
this._ensurePersistentTokenStore();
|
|
974
|
-
const tokenStore =
|
|
1002
|
+
const tokenStore = this._getTokenStore();
|
|
975
1003
|
const userJson = await this._currentServerUserCache.getOrWait([tokenStore], "write-only");
|
|
976
1004
|
return this._currentServerUserFromJson(userJson, tokenStore);
|
|
977
1005
|
}
|
|
@@ -981,7 +1009,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
981
1009
|
}
|
|
982
1010
|
useServerUser(options) {
|
|
983
1011
|
this._ensurePersistentTokenStore();
|
|
984
|
-
const tokenStore =
|
|
1012
|
+
const tokenStore = this._getTokenStore();
|
|
985
1013
|
const userJson = useCache(this._currentServerUserCache, [tokenStore], "useServerUser()");
|
|
986
1014
|
return useMemo(() => {
|
|
987
1015
|
if (options?.required && userJson === null) {
|
|
@@ -992,7 +1020,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
992
1020
|
}
|
|
993
1021
|
onServerUserChange(callback) {
|
|
994
1022
|
this._ensurePersistentTokenStore();
|
|
995
|
-
const tokenStore =
|
|
1023
|
+
const tokenStore = this._getTokenStore();
|
|
996
1024
|
return this._currentServerUserCache.onChange([tokenStore], (userJson) => {
|
|
997
1025
|
callback(this._currentServerUserFromJson(userJson, tokenStore));
|
|
998
1026
|
});
|