@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
package/dist/lib/stack-app.js
CHANGED
|
@@ -47,13 +47,17 @@ var import_stores = require("@stackframe/stack-shared/dist/utils/stores");
|
|
|
47
47
|
var import_clientInterface = require("@stackframe/stack-shared/dist/interface/clientInterface");
|
|
48
48
|
var import_next = require("../utils/next");
|
|
49
49
|
var import_auth = require("./auth");
|
|
50
|
-
var
|
|
50
|
+
var NextNavigationUnscrambled = __toESM(require("next/navigation"));
|
|
51
51
|
var import_url = require("../utils/url");
|
|
52
52
|
var import_objects = require("@stackframe/stack-shared/dist/utils/objects");
|
|
53
53
|
var import_promises = require("@stackframe/stack-shared/dist/utils/promises");
|
|
54
54
|
var import_caches = require("@stackframe/stack-shared/dist/utils/caches");
|
|
55
55
|
var import_react3 = require("@stackframe/stack-shared/dist/utils/react");
|
|
56
|
-
var
|
|
56
|
+
var import_compile_time = require("@stackframe/stack-shared/dist/utils/compile-time");
|
|
57
|
+
var import_stack_sc = require("@stackframe/stack-sc");
|
|
58
|
+
var cookie = __toESM(require("cookie"));
|
|
59
|
+
var NextNavigation = (0, import_compile_time.scrambleDuringCompileTime)(NextNavigationUnscrambled);
|
|
60
|
+
var clientVersion = "js @stackframe/stack@2.4.9";
|
|
57
61
|
function permissionDefinitionScopeToType(scope) {
|
|
58
62
|
return { "any-team": "team", "specific-team": "team", "global": "global" }[scope.type];
|
|
59
63
|
}
|
|
@@ -94,14 +98,11 @@ function getDefaultBaseUrl() {
|
|
|
94
98
|
}
|
|
95
99
|
var defaultBaseUrl = "https://app.stack-auth.com";
|
|
96
100
|
function createEmptyTokenStore() {
|
|
97
|
-
|
|
98
|
-
store.set({
|
|
101
|
+
return new import_stores.AsyncStore({
|
|
99
102
|
refreshToken: null,
|
|
100
103
|
accessToken: null
|
|
101
104
|
});
|
|
102
|
-
return store;
|
|
103
105
|
}
|
|
104
|
-
var memoryTokenStore = createEmptyTokenStore();
|
|
105
106
|
var cookieTokenStore = null;
|
|
106
107
|
var cookieTokenStoreInitializer = () => {
|
|
107
108
|
if (!(0, import_next.isClient)()) {
|
|
@@ -134,33 +135,6 @@ var cookieTokenStoreInitializer = () => {
|
|
|
134
135
|
}
|
|
135
136
|
return cookieTokenStore;
|
|
136
137
|
};
|
|
137
|
-
var tokenStoreInitializers = /* @__PURE__ */ new Map([
|
|
138
|
-
["cookie", cookieTokenStoreInitializer],
|
|
139
|
-
["nextjs-cookie", () => {
|
|
140
|
-
if ((0, import_next.isClient)()) {
|
|
141
|
-
return cookieTokenStoreInitializer();
|
|
142
|
-
} else {
|
|
143
|
-
const store = new import_stores.AsyncStore();
|
|
144
|
-
store.set({
|
|
145
|
-
refreshToken: (0, import_cookie.getCookie)("stack-refresh"),
|
|
146
|
-
accessToken: (0, import_cookie.getCookie)("stack-access")
|
|
147
|
-
});
|
|
148
|
-
store.onChange((value) => {
|
|
149
|
-
try {
|
|
150
|
-
(0, import_cookie.setOrDeleteCookie)("stack-refresh", value.refreshToken, { maxAge: 60 * 60 * 24 * 365 });
|
|
151
|
-
(0, import_cookie.setOrDeleteCookie)("stack-access", value.accessToken, { maxAge: 60 * 60 * 24 });
|
|
152
|
-
} catch (e) {
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
return store;
|
|
156
|
-
}
|
|
157
|
-
}],
|
|
158
|
-
["memory", () => memoryTokenStore],
|
|
159
|
-
[null, () => createEmptyTokenStore()]
|
|
160
|
-
]);
|
|
161
|
-
function getTokenStore(tokenStoreOptions) {
|
|
162
|
-
return (tokenStoreInitializers.get(tokenStoreOptions) ?? (0, import_errors.throwErr)(`Invalid token store ${tokenStoreOptions}`))();
|
|
163
|
-
}
|
|
164
138
|
var loadingSentinel = Symbol("stackAppCacheLoadingSentinel");
|
|
165
139
|
function useCache(cache, dependencies, caller) {
|
|
166
140
|
(0, import_react2.suspendIfSsr)(caller);
|
|
@@ -204,7 +178,7 @@ var createCacheByTokenStore = (fetcher) => {
|
|
|
204
178
|
var _StackClientAppImpl = class __StackClientAppImpl {
|
|
205
179
|
_uniqueIdentifier;
|
|
206
180
|
_interface;
|
|
207
|
-
|
|
181
|
+
_tokenStoreInit;
|
|
208
182
|
_urlOptions;
|
|
209
183
|
__DEMO_ENABLE_SLIGHT_FETCH_DELAY = false;
|
|
210
184
|
_currentUserCache = createCacheByTokenStore(async (tokenStore) => {
|
|
@@ -237,7 +211,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
237
211
|
publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey()
|
|
238
212
|
});
|
|
239
213
|
}
|
|
240
|
-
this.
|
|
214
|
+
this._tokenStoreInit = options.tokenStore;
|
|
241
215
|
this._urlOptions = options.urls ?? {};
|
|
242
216
|
this._uniqueIdentifier = options.uniqueIdentifier ?? (0, import_uuids.generateUuid)();
|
|
243
217
|
if (allClientApps.has(this._uniqueIdentifier)) {
|
|
@@ -245,19 +219,69 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
245
219
|
}
|
|
246
220
|
allClientApps.set(this._uniqueIdentifier, [options.checkString ?? "default check string", this]);
|
|
247
221
|
}
|
|
248
|
-
|
|
249
|
-
|
|
222
|
+
_memoryTokenStore = createEmptyTokenStore();
|
|
223
|
+
_requestTokenStores = /* @__PURE__ */ new Map();
|
|
224
|
+
_getTokenStore(overrideTokenStoreInit) {
|
|
225
|
+
const tokenStoreInit = overrideTokenStoreInit === void 0 ? this._tokenStoreInit : overrideTokenStoreInit;
|
|
226
|
+
switch (tokenStoreInit) {
|
|
227
|
+
case "cookie": {
|
|
228
|
+
return cookieTokenStoreInitializer();
|
|
229
|
+
}
|
|
230
|
+
case "nextjs-cookie": {
|
|
231
|
+
if ((0, import_next.isClient)()) {
|
|
232
|
+
return cookieTokenStoreInitializer();
|
|
233
|
+
} else {
|
|
234
|
+
const store = new import_stores.AsyncStore();
|
|
235
|
+
store.set({
|
|
236
|
+
refreshToken: (0, import_cookie.getCookie)("stack-refresh"),
|
|
237
|
+
accessToken: (0, import_cookie.getCookie)("stack-access")
|
|
238
|
+
});
|
|
239
|
+
store.onChange((value) => {
|
|
240
|
+
try {
|
|
241
|
+
(0, import_cookie.setOrDeleteCookie)("stack-refresh", value.refreshToken, { maxAge: 60 * 60 * 24 * 365 });
|
|
242
|
+
(0, import_cookie.setOrDeleteCookie)("stack-access", value.accessToken, { maxAge: 60 * 60 * 24 });
|
|
243
|
+
} catch (e) {
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
return store;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
case "memory": {
|
|
250
|
+
return this._memoryTokenStore;
|
|
251
|
+
}
|
|
252
|
+
case null: {
|
|
253
|
+
return createEmptyTokenStore();
|
|
254
|
+
}
|
|
255
|
+
default: {
|
|
256
|
+
if (tokenStoreInit && typeof tokenStoreInit === "object" && "headers" in tokenStoreInit) {
|
|
257
|
+
if (this._requestTokenStores.has(tokenStoreInit))
|
|
258
|
+
return this._requestTokenStores.get(tokenStoreInit);
|
|
259
|
+
const cookieHeader = tokenStoreInit.headers.get("cookie");
|
|
260
|
+
const parsed = cookie.parse(cookieHeader || "");
|
|
261
|
+
const res = new import_stores.AsyncStore({
|
|
262
|
+
refreshToken: parsed["stack-refresh"] || null,
|
|
263
|
+
accessToken: parsed["stack-access"] || null
|
|
264
|
+
});
|
|
265
|
+
this._requestTokenStores.set(tokenStoreInit, res);
|
|
266
|
+
return res;
|
|
267
|
+
}
|
|
268
|
+
throw new Error(`Invalid token store ${tokenStoreInit}`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
_hasPersistentTokenStore(overrideTokenStoreInit) {
|
|
273
|
+
return (overrideTokenStoreInit !== void 0 ? overrideTokenStoreInit : this._tokenStoreInit) !== null;
|
|
250
274
|
}
|
|
251
|
-
_ensurePersistentTokenStore() {
|
|
252
|
-
if (!this.
|
|
253
|
-
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.");
|
|
275
|
+
_ensurePersistentTokenStore(overrideTokenStoreInit) {
|
|
276
|
+
if (!this._hasPersistentTokenStore(overrideTokenStoreInit)) {
|
|
277
|
+
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.");
|
|
254
278
|
}
|
|
255
279
|
}
|
|
256
|
-
|
|
280
|
+
_isInternalProject() {
|
|
257
281
|
return this.projectId === "internal";
|
|
258
282
|
}
|
|
259
283
|
_ensureInternalProject() {
|
|
260
|
-
if (!this.
|
|
284
|
+
if (!this._isInternalProject()) {
|
|
261
285
|
throw new Error("Cannot call this function on a Stack app with a project ID other than 'internal'.");
|
|
262
286
|
}
|
|
263
287
|
}
|
|
@@ -324,24 +348,24 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
324
348
|
});
|
|
325
349
|
},
|
|
326
350
|
async listTeams() {
|
|
327
|
-
const teams = await app._currentUserTeamsCache.getOrWait([
|
|
351
|
+
const teams = await app._currentUserTeamsCache.getOrWait([app._getTokenStore()], "write-only");
|
|
328
352
|
return teams.map((json2) => app._teamFromJson(json2));
|
|
329
353
|
},
|
|
330
354
|
useTeams() {
|
|
331
|
-
const teams = useCache(app._currentUserTeamsCache, [
|
|
355
|
+
const teams = useCache(app._currentUserTeamsCache, [app._getTokenStore()], "user.useTeams()");
|
|
332
356
|
return (0, import_react.useMemo)(() => teams.map((json2) => app._teamFromJson(json2)), [teams]);
|
|
333
357
|
},
|
|
334
358
|
onTeamsChange(callback) {
|
|
335
|
-
return app._currentUserTeamsCache.onChange([
|
|
359
|
+
return app._currentUserTeamsCache.onChange([app._getTokenStore()], (value, oldValue) => {
|
|
336
360
|
callback(value.map((json2) => app._teamFromJson(json2)), oldValue?.map((json2) => app._teamFromJson(json2)));
|
|
337
361
|
});
|
|
338
362
|
},
|
|
339
363
|
async listPermissions(scope, options) {
|
|
340
|
-
const permissions = await app._currentUserPermissionsCache.getOrWait([
|
|
364
|
+
const permissions = await app._currentUserPermissionsCache.getOrWait([app._getTokenStore(), scope.id, "team", !!options?.direct], "write-only");
|
|
341
365
|
return permissions.map((json2) => app._permissionFromJson(json2));
|
|
342
366
|
},
|
|
343
367
|
usePermissions(scope, options) {
|
|
344
|
-
const permissions = useCache(app._currentUserPermissionsCache, [
|
|
368
|
+
const permissions = useCache(app._currentUserPermissionsCache, [app._getTokenStore(), scope.id, "team", !!options?.direct], "user.usePermissions()");
|
|
345
369
|
return (0, import_react.useMemo)(() => permissions.map((json2) => app._permissionFromJson(json2)), [permissions]);
|
|
346
370
|
},
|
|
347
371
|
usePermission(scope, permissionId) {
|
|
@@ -392,7 +416,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
392
416
|
return app._updatePassword(options, tokenStore);
|
|
393
417
|
}
|
|
394
418
|
};
|
|
395
|
-
if (this.
|
|
419
|
+
if (this._isInternalProject()) {
|
|
396
420
|
const internalUser = {
|
|
397
421
|
...currentUser,
|
|
398
422
|
createProject(newProject) {
|
|
@@ -467,12 +491,16 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
467
491
|
if (!url) {
|
|
468
492
|
throw new Error(`No URL for handler name ${handlerName}`);
|
|
469
493
|
}
|
|
470
|
-
if (
|
|
471
|
-
|
|
494
|
+
if (import_stack_sc.isReactServer) {
|
|
495
|
+
NextNavigation.redirect(url, options?.replace ? NextNavigation.RedirectType.replace : NextNavigation.RedirectType.push);
|
|
472
496
|
} else {
|
|
473
|
-
|
|
497
|
+
if (options?.replace) {
|
|
498
|
+
window.location.replace(url);
|
|
499
|
+
} else {
|
|
500
|
+
window.location.assign(url);
|
|
501
|
+
}
|
|
502
|
+
await (0, import_promises.wait)(2e3);
|
|
474
503
|
}
|
|
475
|
-
return await (0, import_promises.wait)(2e3);
|
|
476
504
|
}
|
|
477
505
|
async redirectToSignIn() {
|
|
478
506
|
return await this._redirectTo("signIn");
|
|
@@ -534,14 +562,14 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
534
562
|
return await this._interface.verifyEmail(code);
|
|
535
563
|
}
|
|
536
564
|
async getUser(options) {
|
|
537
|
-
this._ensurePersistentTokenStore();
|
|
538
|
-
const tokenStore =
|
|
565
|
+
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
566
|
+
const tokenStore = this._getTokenStore(options?.tokenStore);
|
|
539
567
|
const userJson = await this._currentUserCache.getOrWait([tokenStore], "write-only");
|
|
540
568
|
if (userJson === null) {
|
|
541
569
|
switch (options?.or) {
|
|
542
570
|
case "redirect": {
|
|
543
|
-
|
|
544
|
-
|
|
571
|
+
await this.redirectToSignIn();
|
|
572
|
+
break;
|
|
545
573
|
}
|
|
546
574
|
case "throw": {
|
|
547
575
|
throw new Error("User is not signed in but getUser was called with { or: 'throw' }");
|
|
@@ -554,9 +582,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
554
582
|
return this._currentUserFromJson(userJson, tokenStore);
|
|
555
583
|
}
|
|
556
584
|
useUser(options) {
|
|
557
|
-
this._ensurePersistentTokenStore();
|
|
585
|
+
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
558
586
|
const router = NextNavigation.useRouter();
|
|
559
|
-
const tokenStore =
|
|
587
|
+
const tokenStore = this._getTokenStore(options?.tokenStore);
|
|
560
588
|
const userJson = useCache(this._currentUserCache, [tokenStore], "useUser()");
|
|
561
589
|
if (userJson === null) {
|
|
562
590
|
switch (options?.or) {
|
|
@@ -579,7 +607,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
579
607
|
}
|
|
580
608
|
onUserChange(callback) {
|
|
581
609
|
this._ensurePersistentTokenStore();
|
|
582
|
-
const tokenStore =
|
|
610
|
+
const tokenStore = this._getTokenStore();
|
|
583
611
|
return this._currentUserCache.onChange([tokenStore], (userJson) => {
|
|
584
612
|
callback(this._currentUserFromJson(userJson, tokenStore));
|
|
585
613
|
});
|
|
@@ -595,7 +623,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
595
623
|
}
|
|
596
624
|
async signInWithCredential(options) {
|
|
597
625
|
this._ensurePersistentTokenStore();
|
|
598
|
-
const tokenStore =
|
|
626
|
+
const tokenStore = this._getTokenStore();
|
|
599
627
|
const errorCode = await this._interface.signInWithCredential(options.email, options.password, tokenStore);
|
|
600
628
|
if (!errorCode) {
|
|
601
629
|
await this.redirectToAfterSignIn({ replace: true });
|
|
@@ -604,7 +632,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
604
632
|
}
|
|
605
633
|
async signUpWithCredential(options) {
|
|
606
634
|
this._ensurePersistentTokenStore();
|
|
607
|
-
const tokenStore =
|
|
635
|
+
const tokenStore = this._getTokenStore();
|
|
608
636
|
const emailVerificationRedirectUrl = (0, import_url.constructRedirectUrl)(this.urls.emailVerification);
|
|
609
637
|
const errorCode = await this._interface.signUpWithCredential(
|
|
610
638
|
options.email,
|
|
@@ -619,7 +647,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
619
647
|
}
|
|
620
648
|
async signInWithMagicLink(code) {
|
|
621
649
|
this._ensurePersistentTokenStore();
|
|
622
|
-
const tokenStore =
|
|
650
|
+
const tokenStore = this._getTokenStore();
|
|
623
651
|
const result = await this._interface.signInWithMagicLink(code, tokenStore);
|
|
624
652
|
if (result instanceof import_stack_shared.KnownError) {
|
|
625
653
|
return result;
|
|
@@ -632,7 +660,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
632
660
|
}
|
|
633
661
|
async callOAuthCallback() {
|
|
634
662
|
this._ensurePersistentTokenStore();
|
|
635
|
-
const tokenStore =
|
|
663
|
+
const tokenStore = this._getTokenStore();
|
|
636
664
|
const result = await (0, import_auth.callOAuthCallback)(this._interface, tokenStore, this.urls.oauthCallback);
|
|
637
665
|
if (result) {
|
|
638
666
|
if (result.newUser) {
|
|
@@ -673,7 +701,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
673
701
|
}
|
|
674
702
|
async _listOwnedProjects() {
|
|
675
703
|
this._ensureInternalProject();
|
|
676
|
-
const tokenStore =
|
|
704
|
+
const tokenStore = this._getTokenStore();
|
|
677
705
|
const json = await this._ownedProjectsCache.getOrWait([tokenStore], "write-only");
|
|
678
706
|
return json.map((j) => this._projectAdminFromJson(
|
|
679
707
|
j,
|
|
@@ -683,7 +711,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
683
711
|
}
|
|
684
712
|
_useOwnedProjects() {
|
|
685
713
|
this._ensureInternalProject();
|
|
686
|
-
const tokenStore =
|
|
714
|
+
const tokenStore = this._getTokenStore();
|
|
687
715
|
const json = useCache(this._ownedProjectsCache, [tokenStore], "useOwnedProjects()");
|
|
688
716
|
return (0, import_react.useMemo)(() => json.map((j) => this._projectAdminFromJson(
|
|
689
717
|
j,
|
|
@@ -693,7 +721,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
693
721
|
}
|
|
694
722
|
_onOwnedProjectsChange(callback) {
|
|
695
723
|
this._ensureInternalProject();
|
|
696
|
-
const tokenStore =
|
|
724
|
+
const tokenStore = this._getTokenStore();
|
|
697
725
|
return this._ownedProjectsCache.onChange([tokenStore], (projects) => {
|
|
698
726
|
callback(projects.map((j) => this._projectAdminFromJson(
|
|
699
727
|
j,
|
|
@@ -704,7 +732,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
704
732
|
}
|
|
705
733
|
async _createProject(newProject) {
|
|
706
734
|
this._ensureInternalProject();
|
|
707
|
-
const tokenStore =
|
|
735
|
+
const tokenStore = this._getTokenStore();
|
|
708
736
|
const json = await this._interface.createProject(newProject, tokenStore);
|
|
709
737
|
const res = this._projectAdminFromJson(
|
|
710
738
|
json,
|
|
@@ -756,13 +784,13 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
756
784
|
baseUrl: this._interface.options.baseUrl,
|
|
757
785
|
projectId: this.projectId,
|
|
758
786
|
publishableClientKey: this._interface.options.publishableClientKey,
|
|
759
|
-
tokenStore: this.
|
|
787
|
+
tokenStore: this._tokenStoreInit,
|
|
760
788
|
urls: this._urlOptions,
|
|
761
789
|
uniqueIdentifier: this._uniqueIdentifier
|
|
762
790
|
};
|
|
763
791
|
},
|
|
764
792
|
setCurrentUser: (userJsonPromise) => {
|
|
765
|
-
(0, import_promises.runAsynchronously)(this._currentUserCache.forceSetCachedValueAsync([
|
|
793
|
+
(0, import_promises.runAsynchronously)(this._currentUserCache.forceSetCachedValueAsync([this._getTokenStore()], userJsonPromise));
|
|
766
794
|
}
|
|
767
795
|
};
|
|
768
796
|
}
|
|
@@ -858,15 +886,15 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
858
886
|
});
|
|
859
887
|
},
|
|
860
888
|
async listTeams() {
|
|
861
|
-
const teams = await app._serverTeamsCache.getOrWait([
|
|
889
|
+
const teams = await app._serverTeamsCache.getOrWait([app._getTokenStore()], "write-only");
|
|
862
890
|
return teams.map((json2) => app._serverTeamFromJson(json2));
|
|
863
891
|
},
|
|
864
892
|
useTeams() {
|
|
865
|
-
const teams = useCache(app._serverTeamsCache, [
|
|
893
|
+
const teams = useCache(app._serverTeamsCache, [app._getTokenStore()], "user.useTeams()");
|
|
866
894
|
return (0, import_react.useMemo)(() => teams.map((json2) => app._serverTeamFromJson(json2)), [teams]);
|
|
867
895
|
},
|
|
868
896
|
onTeamsChange(callback) {
|
|
869
|
-
return app._serverTeamsCache.onChange([
|
|
897
|
+
return app._serverTeamsCache.onChange([app._getTokenStore()], (value, oldValue) => {
|
|
870
898
|
callback(value.map((json2) => app._serverTeamFromJson(json2)), oldValue?.map((json2) => app._serverTeamFromJson(json2)));
|
|
871
899
|
});
|
|
872
900
|
},
|
|
@@ -929,7 +957,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
929
957
|
return app._updatePassword(options, tokenStore);
|
|
930
958
|
}
|
|
931
959
|
};
|
|
932
|
-
if (this.
|
|
960
|
+
if (this._isInternalProject()) {
|
|
933
961
|
const internalUser = {
|
|
934
962
|
...currentUser,
|
|
935
963
|
createProject(newProject) {
|
|
@@ -1008,7 +1036,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1008
1036
|
}
|
|
1009
1037
|
async getServerUser() {
|
|
1010
1038
|
this._ensurePersistentTokenStore();
|
|
1011
|
-
const tokenStore =
|
|
1039
|
+
const tokenStore = this._getTokenStore();
|
|
1012
1040
|
const userJson = await this._currentServerUserCache.getOrWait([tokenStore], "write-only");
|
|
1013
1041
|
return this._currentServerUserFromJson(userJson, tokenStore);
|
|
1014
1042
|
}
|
|
@@ -1018,7 +1046,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1018
1046
|
}
|
|
1019
1047
|
useServerUser(options) {
|
|
1020
1048
|
this._ensurePersistentTokenStore();
|
|
1021
|
-
const tokenStore =
|
|
1049
|
+
const tokenStore = this._getTokenStore();
|
|
1022
1050
|
const userJson = useCache(this._currentServerUserCache, [tokenStore], "useServerUser()");
|
|
1023
1051
|
return (0, import_react.useMemo)(() => {
|
|
1024
1052
|
if (options?.required && userJson === null) {
|
|
@@ -1029,7 +1057,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1029
1057
|
}
|
|
1030
1058
|
onServerUserChange(callback) {
|
|
1031
1059
|
this._ensurePersistentTokenStore();
|
|
1032
|
-
const tokenStore =
|
|
1060
|
+
const tokenStore = this._getTokenStore();
|
|
1033
1061
|
return this._currentServerUserCache.onChange([tokenStore], (userJson) => {
|
|
1034
1062
|
callback(this._currentServerUserFromJson(userJson, tokenStore));
|
|
1035
1063
|
});
|