@stackframe/stack 2.5.8 → 2.5.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/CHANGELOG.md +10 -0
- package/dist/components/credential-sign-in.d.mts +5 -0
- package/dist/components/credential-sign-in.d.ts +5 -0
- package/dist/components/{credential-sign-in-form.js → credential-sign-in.js} +8 -8
- package/dist/components/credential-sign-in.js.map +1 -0
- package/dist/components/credential-sign-up.d.mts +5 -0
- package/dist/components/credential-sign-up.d.ts +5 -0
- package/dist/components/{credential-sign-up-form.js → credential-sign-up.js} +8 -8
- package/dist/components/credential-sign-up.js.map +1 -0
- package/dist/components/elements/user-avatar.d.mts +1 -1
- package/dist/components/elements/user-avatar.d.ts +1 -1
- package/dist/components/magic-link-sign-in.d.mts +5 -0
- package/dist/components/magic-link-sign-in.d.ts +5 -0
- package/dist/components/{magic-link-sign-in-form.js → magic-link-sign-in.js} +8 -8
- package/dist/components/magic-link-sign-in.js.map +1 -0
- package/dist/components/message-cards/predefined-message-card.js +8 -8
- package/dist/components/message-cards/predefined-message-card.js.map +1 -1
- package/dist/components/selected-team-switcher.d.mts +1 -1
- package/dist/components/selected-team-switcher.d.ts +1 -1
- package/dist/components/user-button.js +3 -3
- package/dist/components/user-button.js.map +1 -1
- package/dist/components-page/account-settings.js +4 -4
- package/dist/components-page/account-settings.js.map +1 -1
- package/dist/components-page/auth-page.js +21 -8
- package/dist/components-page/auth-page.js.map +1 -1
- package/dist/components-page/stack-handler.d.mts +2 -2
- package/dist/components-page/stack-handler.d.ts +2 -2
- package/dist/components-page/stack-handler.js +8 -15
- package/dist/components-page/stack-handler.js.map +1 -1
- package/dist/esm/components/{credential-sign-in-form.js → credential-sign-in.js} +4 -4
- package/dist/esm/components/credential-sign-in.js.map +1 -0
- package/dist/esm/components/{credential-sign-up-form.js → credential-sign-up.js} +4 -4
- package/dist/esm/components/credential-sign-up.js.map +1 -0
- package/dist/esm/components/{magic-link-sign-in-form.js → magic-link-sign-in.js} +4 -4
- package/dist/esm/components/magic-link-sign-in.js.map +1 -0
- package/dist/esm/components/message-cards/predefined-message-card.js +8 -8
- package/dist/esm/components/message-cards/predefined-message-card.js.map +1 -1
- package/dist/esm/components/user-button.js +3 -3
- package/dist/esm/components/user-button.js.map +1 -1
- package/dist/esm/components-page/account-settings.js +4 -4
- package/dist/esm/components-page/account-settings.js.map +1 -1
- package/dist/esm/components-page/auth-page.js +21 -8
- package/dist/esm/components-page/auth-page.js.map +1 -1
- package/dist/esm/components-page/stack-handler.js +8 -15
- package/dist/esm/components-page/stack-handler.js.map +1 -1
- package/dist/esm/index.js +7 -9
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/auth.js +3 -3
- package/dist/esm/lib/auth.js.map +1 -1
- package/dist/esm/lib/cookie.js +8 -6
- package/dist/esm/lib/cookie.js.map +1 -1
- package/dist/esm/lib/stack-app.js +139 -91
- package/dist/esm/lib/stack-app.js.map +1 -1
- package/dist/esm/providers/stack-provider-client.js +1 -3
- package/dist/esm/providers/stack-provider-client.js.map +1 -1
- package/dist/esm/utils/url.js +9 -1
- package/dist/esm/utils/url.js.map +1 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +6 -8
- package/dist/index.js.map +1 -1
- package/dist/lib/auth.js +3 -3
- package/dist/lib/auth.js.map +1 -1
- package/dist/lib/cookie.js +6 -6
- package/dist/lib/cookie.js.map +1 -1
- package/dist/lib/hooks.d.mts +1 -1
- package/dist/lib/hooks.d.ts +1 -1
- package/dist/lib/stack-app.d.mts +58 -23
- package/dist/lib/stack-app.d.ts +58 -23
- package/dist/lib/stack-app.js +139 -91
- package/dist/lib/stack-app.js.map +1 -1
- package/dist/providers/stack-provider-client.d.mts +1 -1
- package/dist/providers/stack-provider-client.d.ts +1 -1
- package/dist/providers/stack-provider-client.js +1 -3
- package/dist/providers/stack-provider-client.js.map +1 -1
- package/dist/providers/stack-provider.d.mts +1 -1
- package/dist/providers/stack-provider.d.ts +1 -1
- package/dist/utils/url.js +9 -1
- package/dist/utils/url.js.map +1 -1
- package/package.json +6 -4
- package/dist/components/credential-sign-in-form.d.mts +0 -5
- package/dist/components/credential-sign-in-form.d.ts +0 -5
- package/dist/components/credential-sign-in-form.js.map +0 -1
- package/dist/components/credential-sign-up-form.d.mts +0 -5
- package/dist/components/credential-sign-up-form.d.ts +0 -5
- package/dist/components/credential-sign-up-form.js.map +0 -1
- package/dist/components/magic-link-sign-in-form.d.mts +0 -5
- package/dist/components/magic-link-sign-in-form.d.ts +0 -5
- package/dist/components/magic-link-sign-in-form.js.map +0 -1
- package/dist/esm/components/credential-sign-in-form.js.map +0 -1
- package/dist/esm/components/credential-sign-up-form.js.map +0 -1
- package/dist/esm/components/magic-link-sign-in-form.js.map +0 -1
package/dist/lib/stack-app.js
CHANGED
|
@@ -53,6 +53,7 @@ var import_react = require("@stackframe/stack-shared/dist/utils/react");
|
|
|
53
53
|
var import_results = require("@stackframe/stack-shared/dist/utils/results");
|
|
54
54
|
var import_stores = require("@stackframe/stack-shared/dist/utils/stores");
|
|
55
55
|
var import_strings = require("@stackframe/stack-shared/dist/utils/strings");
|
|
56
|
+
var import_urls = require("@stackframe/stack-shared/dist/utils/urls");
|
|
56
57
|
var import_uuids = require("@stackframe/stack-shared/dist/utils/uuids");
|
|
57
58
|
var cookie = __toESM(require("cookie"));
|
|
58
59
|
var NextNavigationUnscrambled = __toESM(require("next/navigation"));
|
|
@@ -61,23 +62,25 @@ var import_url = require("../utils/url");
|
|
|
61
62
|
var import_auth = require("./auth");
|
|
62
63
|
var import_cookie = require("./cookie");
|
|
63
64
|
var NextNavigation = (0, import_compile_time.scrambleDuringCompileTime)(NextNavigationUnscrambled);
|
|
64
|
-
var clientVersion = "js @stackframe/stack@2.5.
|
|
65
|
+
var clientVersion = "js @stackframe/stack@2.5.9";
|
|
65
66
|
function getUrls(partial) {
|
|
66
67
|
const handler = partial.handler ?? "/handler";
|
|
68
|
+
const home = partial.home ?? "/";
|
|
69
|
+
const afterSignIn = partial.afterSignIn ?? home;
|
|
67
70
|
return {
|
|
68
71
|
handler,
|
|
69
72
|
signIn: `${handler}/sign-in`,
|
|
70
|
-
afterSignIn:
|
|
73
|
+
afterSignIn: home,
|
|
71
74
|
signUp: `${handler}/sign-up`,
|
|
72
|
-
afterSignUp:
|
|
75
|
+
afterSignUp: afterSignIn,
|
|
73
76
|
signOut: `${handler}/sign-out`,
|
|
74
|
-
afterSignOut:
|
|
77
|
+
afterSignOut: home,
|
|
75
78
|
emailVerification: `${handler}/email-verification`,
|
|
76
79
|
passwordReset: `${handler}/password-reset`,
|
|
77
80
|
forgotPassword: `${handler}/forgot-password`,
|
|
78
81
|
oauthCallback: `${handler}/oauth-callback`,
|
|
79
82
|
magicLinkCallback: `${handler}/magic-link-callback`,
|
|
80
|
-
home
|
|
83
|
+
home,
|
|
81
84
|
accountSettings: `${handler}/account-settings`,
|
|
82
85
|
error: `${handler}/error`,
|
|
83
86
|
...(0, import_objects.filterUndefined)(partial)
|
|
@@ -85,7 +88,7 @@ function getUrls(partial) {
|
|
|
85
88
|
}
|
|
86
89
|
async function _redirectTo(url, options) {
|
|
87
90
|
if (import_stack_sc.isReactServer) {
|
|
88
|
-
NextNavigation.redirect(url, options?.replace ? NextNavigation.RedirectType.replace : NextNavigation.RedirectType.push);
|
|
91
|
+
NextNavigation.redirect(url.toString(), options?.replace ? NextNavigation.RedirectType.replace : NextNavigation.RedirectType.push);
|
|
89
92
|
} else {
|
|
90
93
|
if (options?.replace) {
|
|
91
94
|
window.location.replace(url);
|
|
@@ -188,7 +191,10 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
188
191
|
this._currentUserOAuthConnectionAccessTokensCache = createCacheBySession(
|
|
189
192
|
async (session, [accountId, scope]) => {
|
|
190
193
|
try {
|
|
191
|
-
|
|
194
|
+
const result = await this._interface.createProviderAccessToken(accountId, scope || "", session);
|
|
195
|
+
return {
|
|
196
|
+
accessToken: result.access_token
|
|
197
|
+
};
|
|
192
198
|
} catch (err) {
|
|
193
199
|
if (!(err instanceof import_stack_shared.KnownErrors.OAuthConnectionDoesNotHaveRequiredScope || err instanceof import_stack_shared.KnownErrors.OAuthConnectionNotConnectedToUser)) {
|
|
194
200
|
throw err;
|
|
@@ -300,12 +306,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
300
306
|
}
|
|
301
307
|
return this._uniqueIdentifier;
|
|
302
308
|
}
|
|
303
|
-
async _checkFeatureSupport(
|
|
304
|
-
return await this._interface.checkFeatureSupport({ ...options,
|
|
309
|
+
async _checkFeatureSupport(name, options) {
|
|
310
|
+
return await this._interface.checkFeatureSupport({ ...options, name });
|
|
305
311
|
}
|
|
306
|
-
_useCheckFeatureSupport(
|
|
307
|
-
(0, import_promises.runAsynchronously)(this._checkFeatureSupport(
|
|
308
|
-
throw new import_errors.StackAssertionError(`${
|
|
312
|
+
_useCheckFeatureSupport(name, options) {
|
|
313
|
+
(0, import_promises.runAsynchronously)(this._checkFeatureSupport(name, options));
|
|
314
|
+
throw new import_errors.StackAssertionError(`${name} is not currently supported. Please reach out to Stack support for more information.`);
|
|
309
315
|
}
|
|
310
316
|
get _refreshTokenCookieName() {
|
|
311
317
|
return `stack-refresh-${this.projectId}`;
|
|
@@ -568,7 +574,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
568
574
|
}
|
|
569
575
|
};
|
|
570
576
|
}
|
|
571
|
-
|
|
577
|
+
_createUserExtra(crud, session) {
|
|
572
578
|
const app = this;
|
|
573
579
|
async function getConnectedAccount(id, options) {
|
|
574
580
|
const scopeString = options?.scopes?.join(" ");
|
|
@@ -638,7 +644,10 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
638
644
|
return app._updateClientUser(update, session);
|
|
639
645
|
},
|
|
640
646
|
sendVerificationEmail() {
|
|
641
|
-
|
|
647
|
+
if (!crud?.primary_email) {
|
|
648
|
+
throw new import_errors.StackAssertionError("User does not have a primary email");
|
|
649
|
+
}
|
|
650
|
+
return app._sendVerificationEmail(crud.primary_email, session);
|
|
642
651
|
},
|
|
643
652
|
updatePassword(options) {
|
|
644
653
|
return app._updatePassword(options, session);
|
|
@@ -664,7 +673,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
664
673
|
const currentUser = {
|
|
665
674
|
...this._createBaseUser(crud),
|
|
666
675
|
...this._createAuth(session),
|
|
667
|
-
...this.
|
|
676
|
+
...this._createUserExtra(crud, session),
|
|
668
677
|
...this._isInternalProject() ? this._createInternalUserExtra(session) : {}
|
|
669
678
|
};
|
|
670
679
|
Object.freeze(currentUser);
|
|
@@ -685,57 +694,93 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
685
694
|
get projectId() {
|
|
686
695
|
return this._interface.projectId;
|
|
687
696
|
}
|
|
697
|
+
async _isTrusted(url) {
|
|
698
|
+
return (0, import_urls.isRelative)(url);
|
|
699
|
+
}
|
|
688
700
|
get urls() {
|
|
689
701
|
return getUrls(this._urlOptions);
|
|
690
702
|
}
|
|
691
|
-
async
|
|
692
|
-
|
|
703
|
+
async _redirectIfTrusted(url, options) {
|
|
704
|
+
if (!await this._isTrusted(url)) {
|
|
705
|
+
throw new Error(`Redirect URL ${url} is not trusted; should be relative.`);
|
|
706
|
+
}
|
|
707
|
+
return await _redirectTo(url, options);
|
|
708
|
+
}
|
|
709
|
+
async _redirectToHandler(handlerName, options) {
|
|
710
|
+
let url = this.urls[handlerName];
|
|
693
711
|
if (!url) {
|
|
694
712
|
throw new Error(`No URL for handler name ${handlerName}`);
|
|
695
713
|
}
|
|
696
|
-
|
|
714
|
+
if (handlerName === "afterSignIn" || handlerName === "afterSignUp") {
|
|
715
|
+
if (import_stack_sc.isReactServer || typeof window === "undefined") {
|
|
716
|
+
try {
|
|
717
|
+
await this._checkFeatureSupport("rsc-handler-" + handlerName, {});
|
|
718
|
+
} catch (e) {
|
|
719
|
+
}
|
|
720
|
+
} else {
|
|
721
|
+
const queryParams = new URLSearchParams(window.location.search);
|
|
722
|
+
url = queryParams.get("after_auth_return_to") || url;
|
|
723
|
+
}
|
|
724
|
+
} else if (handlerName === "signIn" || handlerName === "signUp") {
|
|
725
|
+
if (import_stack_sc.isReactServer || typeof window === "undefined") {
|
|
726
|
+
try {
|
|
727
|
+
await this._checkFeatureSupport("rsc-handler-" + handlerName, {});
|
|
728
|
+
} catch (e) {
|
|
729
|
+
}
|
|
730
|
+
} else {
|
|
731
|
+
const currentUrl = new URL(window.location.href);
|
|
732
|
+
const nextUrl = new URL(url, currentUrl);
|
|
733
|
+
if (currentUrl.searchParams.has("after_auth_return_to")) {
|
|
734
|
+
nextUrl.searchParams.set("after_auth_return_to", currentUrl.searchParams.get("after_auth_return_to"));
|
|
735
|
+
} else if (currentUrl.protocol === nextUrl.protocol && currentUrl.host === nextUrl.host) {
|
|
736
|
+
nextUrl.searchParams.set("after_auth_return_to", (0, import_urls.getRelativePart)(currentUrl));
|
|
737
|
+
}
|
|
738
|
+
url = (0, import_urls.getRelativePart)(nextUrl);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
await this._redirectIfTrusted(url, options);
|
|
697
742
|
}
|
|
698
|
-
async redirectToSignIn() {
|
|
699
|
-
return await this.
|
|
743
|
+
async redirectToSignIn(options) {
|
|
744
|
+
return await this._redirectToHandler("signIn", options);
|
|
700
745
|
}
|
|
701
|
-
async redirectToSignUp() {
|
|
702
|
-
return await this.
|
|
746
|
+
async redirectToSignUp(options) {
|
|
747
|
+
return await this._redirectToHandler("signUp", options);
|
|
703
748
|
}
|
|
704
|
-
async redirectToSignOut() {
|
|
705
|
-
return await this.
|
|
749
|
+
async redirectToSignOut(options) {
|
|
750
|
+
return await this._redirectToHandler("signOut", options);
|
|
706
751
|
}
|
|
707
|
-
async redirectToEmailVerification() {
|
|
708
|
-
return await this.
|
|
752
|
+
async redirectToEmailVerification(options) {
|
|
753
|
+
return await this._redirectToHandler("emailVerification", options);
|
|
709
754
|
}
|
|
710
|
-
async redirectToPasswordReset() {
|
|
711
|
-
return await this.
|
|
755
|
+
async redirectToPasswordReset(options) {
|
|
756
|
+
return await this._redirectToHandler("passwordReset", options);
|
|
712
757
|
}
|
|
713
|
-
async redirectToForgotPassword() {
|
|
714
|
-
return await this.
|
|
758
|
+
async redirectToForgotPassword(options) {
|
|
759
|
+
return await this._redirectToHandler("forgotPassword", options);
|
|
715
760
|
}
|
|
716
|
-
async redirectToHome() {
|
|
717
|
-
return await this.
|
|
761
|
+
async redirectToHome(options) {
|
|
762
|
+
return await this._redirectToHandler("home", options);
|
|
718
763
|
}
|
|
719
|
-
async redirectToOAuthCallback() {
|
|
720
|
-
return await this.
|
|
764
|
+
async redirectToOAuthCallback(options) {
|
|
765
|
+
return await this._redirectToHandler("oauthCallback", options);
|
|
721
766
|
}
|
|
722
|
-
async redirectToMagicLinkCallback() {
|
|
723
|
-
return await this.
|
|
767
|
+
async redirectToMagicLinkCallback(options) {
|
|
768
|
+
return await this._redirectToHandler("magicLinkCallback", options);
|
|
724
769
|
}
|
|
725
|
-
async redirectToAfterSignIn() {
|
|
726
|
-
return await this.
|
|
770
|
+
async redirectToAfterSignIn(options) {
|
|
771
|
+
return await this._redirectToHandler("afterSignIn", options);
|
|
727
772
|
}
|
|
728
|
-
async redirectToAfterSignUp() {
|
|
729
|
-
return await this.
|
|
773
|
+
async redirectToAfterSignUp(options) {
|
|
774
|
+
return await this._redirectToHandler("afterSignUp", options);
|
|
730
775
|
}
|
|
731
|
-
async redirectToAfterSignOut() {
|
|
732
|
-
return await this.
|
|
776
|
+
async redirectToAfterSignOut(options) {
|
|
777
|
+
return await this._redirectToHandler("afterSignOut", options);
|
|
733
778
|
}
|
|
734
|
-
async redirectToAccountSettings() {
|
|
735
|
-
return await this.
|
|
779
|
+
async redirectToAccountSettings(options) {
|
|
780
|
+
return await this._redirectToHandler("accountSettings", options);
|
|
736
781
|
}
|
|
737
|
-
async redirectToError() {
|
|
738
|
-
return await this.
|
|
782
|
+
async redirectToError(options) {
|
|
783
|
+
return await this._redirectToHandler("error", options);
|
|
739
784
|
}
|
|
740
785
|
async sendForgotPasswordEmail(email) {
|
|
741
786
|
const redirectUrl = (0, import_url.constructRedirectUrl)(this.urls.passwordReset);
|
|
@@ -764,7 +809,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
764
809
|
if (crud === null) {
|
|
765
810
|
switch (options?.or) {
|
|
766
811
|
case "redirect": {
|
|
767
|
-
await this.redirectToSignIn();
|
|
812
|
+
await this.redirectToSignIn({ replace: true });
|
|
768
813
|
break;
|
|
769
814
|
}
|
|
770
815
|
case "throw": {
|
|
@@ -785,7 +830,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
785
830
|
if (crud === null) {
|
|
786
831
|
switch (options?.or) {
|
|
787
832
|
case "redirect": {
|
|
788
|
-
|
|
833
|
+
(0, import_promises.runAsynchronously)(this.redirectToSignIn({ replace: true }));
|
|
789
834
|
(0, import_react.suspend)();
|
|
790
835
|
throw new import_errors.StackAssertionError("suspend should never return");
|
|
791
836
|
}
|
|
@@ -879,9 +924,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
879
924
|
await this._interface.signOut(session);
|
|
880
925
|
await this.redirectToAfterSignOut();
|
|
881
926
|
}
|
|
882
|
-
async _sendVerificationEmail(session) {
|
|
927
|
+
async _sendVerificationEmail(email, session) {
|
|
883
928
|
const emailVerificationRedirectUrl = (0, import_url.constructRedirectUrl)(this.urls.emailVerification);
|
|
884
|
-
return await this._interface.sendVerificationEmail(emailVerificationRedirectUrl, session);
|
|
929
|
+
return await this._interface.sendVerificationEmail(email, emailVerificationRedirectUrl, session);
|
|
885
930
|
}
|
|
886
931
|
async _updatePassword(options, session) {
|
|
887
932
|
return await this._interface.updatePassword(options, session);
|
|
@@ -1026,7 +1071,13 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1026
1071
|
return await this._interface.listServerTeamMemberPermissions({ teamId, userId, recursive });
|
|
1027
1072
|
});
|
|
1028
1073
|
}
|
|
1074
|
+
async _updateServerUser(userId, update) {
|
|
1075
|
+
const result = await this._interface.updateServerUser(userId, userUpdateOptionsToCrud(update));
|
|
1076
|
+
await this._refreshUsers();
|
|
1077
|
+
return result;
|
|
1078
|
+
}
|
|
1029
1079
|
_createBaseUser(crud) {
|
|
1080
|
+
const app = this;
|
|
1030
1081
|
if (!crud) {
|
|
1031
1082
|
throw new import_errors.StackAssertionError("User not found");
|
|
1032
1083
|
}
|
|
@@ -1035,10 +1086,41 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1035
1086
|
..."server_metadata" in crud ? {
|
|
1036
1087
|
// server user
|
|
1037
1088
|
serverMetadata: crud.server_metadata
|
|
1038
|
-
} : {}
|
|
1089
|
+
} : {},
|
|
1090
|
+
async setServerMetadata(metadata) {
|
|
1091
|
+
await app._updateServerUser(crud.id, { serverMetadata: metadata });
|
|
1092
|
+
},
|
|
1093
|
+
async setPrimaryEmail(email, options) {
|
|
1094
|
+
await app._updateServerUser(crud.id, { primaryEmail: email, primaryEmailVerified: options?.verified });
|
|
1095
|
+
},
|
|
1096
|
+
async grantPermission(scope, permissionId) {
|
|
1097
|
+
await app._interface.grantServerTeamUserPermission(scope.id, crud.id, permissionId);
|
|
1098
|
+
for (const recursive of [true, false]) {
|
|
1099
|
+
await app._serverTeamUserPermissionsCache.refresh([scope.id, crud.id, recursive]);
|
|
1100
|
+
}
|
|
1101
|
+
},
|
|
1102
|
+
async revokePermission(scope, permissionId) {
|
|
1103
|
+
await app._interface.revokeServerTeamUserPermission(scope.id, crud.id, permissionId);
|
|
1104
|
+
for (const recursive of [true, false]) {
|
|
1105
|
+
await app._serverTeamUserPermissionsCache.refresh([scope.id, crud.id, recursive]);
|
|
1106
|
+
}
|
|
1107
|
+
},
|
|
1108
|
+
async delete() {
|
|
1109
|
+
const res = await app._interface.deleteServerServerUser(crud.id);
|
|
1110
|
+
await app._refreshUsers();
|
|
1111
|
+
return res;
|
|
1112
|
+
},
|
|
1113
|
+
async createSession(options) {
|
|
1114
|
+
const tokens = await app._interface.createServerUserSession(crud.id, options.expiresInMillis ?? 1e3 * 60 * 60 * 24 * 365);
|
|
1115
|
+
return {
|
|
1116
|
+
async getTokens() {
|
|
1117
|
+
return tokens;
|
|
1118
|
+
}
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1039
1121
|
};
|
|
1040
1122
|
}
|
|
1041
|
-
|
|
1123
|
+
_createUserExtra(crud) {
|
|
1042
1124
|
if (!crud) {
|
|
1043
1125
|
throw new import_errors.StackAssertionError("User not found");
|
|
1044
1126
|
}
|
|
@@ -1050,15 +1132,9 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1050
1132
|
async setClientMetadata(metadata) {
|
|
1051
1133
|
return await this.update({ clientMetadata: metadata });
|
|
1052
1134
|
},
|
|
1053
|
-
async setServerMetadata(metadata) {
|
|
1054
|
-
return await this.update({ serverMetadata: metadata });
|
|
1055
|
-
},
|
|
1056
1135
|
async setSelectedTeam(team) {
|
|
1057
1136
|
return await this.update({ selectedTeamId: team?.id ?? null });
|
|
1058
1137
|
},
|
|
1059
|
-
async setPrimaryEmail(email, options) {
|
|
1060
|
-
return await this.update({ primaryEmail: email, primaryEmailVerified: options?.verified });
|
|
1061
|
-
},
|
|
1062
1138
|
getConnectedAccount: async () => {
|
|
1063
1139
|
return await app._checkFeatureSupport("getConnectedAccount() on ServerUser", {});
|
|
1064
1140
|
},
|
|
@@ -1105,26 +1181,8 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1105
1181
|
async hasPermission(scope, permissionId) {
|
|
1106
1182
|
return await this.getPermission(scope, permissionId) !== null;
|
|
1107
1183
|
},
|
|
1108
|
-
async grantPermission(scope, permissionId) {
|
|
1109
|
-
await app._interface.grantServerTeamUserPermission(scope.id, crud.id, permissionId);
|
|
1110
|
-
for (const recursive of [true, false]) {
|
|
1111
|
-
await app._serverTeamUserPermissionsCache.refresh([scope.id, crud.id, recursive]);
|
|
1112
|
-
}
|
|
1113
|
-
},
|
|
1114
|
-
async revokePermission(scope, permissionId) {
|
|
1115
|
-
await app._interface.revokeServerTeamUserPermission(scope.id, crud.id, permissionId);
|
|
1116
|
-
for (const recursive of [true, false]) {
|
|
1117
|
-
await app._serverTeamUserPermissionsCache.refresh([scope.id, crud.id, recursive]);
|
|
1118
|
-
}
|
|
1119
|
-
},
|
|
1120
|
-
async delete() {
|
|
1121
|
-
const res = await app._interface.deleteServerServerUser(crud.id);
|
|
1122
|
-
await app._refreshUsers();
|
|
1123
|
-
return res;
|
|
1124
|
-
},
|
|
1125
1184
|
async update(update) {
|
|
1126
|
-
|
|
1127
|
-
await app._refreshUsers();
|
|
1185
|
+
await app._updateServerUser(crud.id, update);
|
|
1128
1186
|
},
|
|
1129
1187
|
async sendVerificationEmail() {
|
|
1130
1188
|
return await app._checkFeatureSupport("sendVerificationEmail() on ServerUser", {});
|
|
@@ -1136,8 +1194,8 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1136
1194
|
}
|
|
1137
1195
|
_serverUserFromCrud(crud) {
|
|
1138
1196
|
return {
|
|
1139
|
-
...this.
|
|
1140
|
-
...this.
|
|
1197
|
+
...this._createUserExtra(crud),
|
|
1198
|
+
...this._createBaseUser(crud)
|
|
1141
1199
|
};
|
|
1142
1200
|
}
|
|
1143
1201
|
_currentUserFromCrud(crud, session) {
|
|
@@ -1195,7 +1253,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1195
1253
|
if (crud === null) {
|
|
1196
1254
|
switch (options?.or) {
|
|
1197
1255
|
case "redirect": {
|
|
1198
|
-
await this.redirectToSignIn();
|
|
1256
|
+
await this.redirectToSignIn({ replace: true });
|
|
1199
1257
|
break;
|
|
1200
1258
|
}
|
|
1201
1259
|
case "throw": {
|
|
@@ -1224,7 +1282,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1224
1282
|
if (crud === null) {
|
|
1225
1283
|
switch (options?.or) {
|
|
1226
1284
|
case "redirect": {
|
|
1227
|
-
|
|
1285
|
+
(0, import_promises.runAsynchronously)(this.redirectToSignIn({ replace: true }));
|
|
1228
1286
|
(0, import_react.suspend)();
|
|
1229
1287
|
throw new import_errors.StackAssertionError("suspend should never return");
|
|
1230
1288
|
}
|
|
@@ -1540,16 +1598,6 @@ function userUpdateOptionsToCrud(options) {
|
|
|
1540
1598
|
selected_team_id: options.selectedTeamId
|
|
1541
1599
|
};
|
|
1542
1600
|
}
|
|
1543
|
-
function serverUserUpdateOptionsToCrud(options) {
|
|
1544
|
-
return {
|
|
1545
|
-
display_name: options.displayName,
|
|
1546
|
-
client_metadata: options.clientMetadata,
|
|
1547
|
-
selected_team_id: options.selectedTeamId,
|
|
1548
|
-
primary_email: options.primaryEmail,
|
|
1549
|
-
primary_email_verified: options.primaryEmailVerified,
|
|
1550
|
-
server_metadata: options.serverMetadata
|
|
1551
|
-
};
|
|
1552
|
-
}
|
|
1553
1601
|
function adminProjectUpdateOptionsToCrud(options) {
|
|
1554
1602
|
return {
|
|
1555
1603
|
display_name: options.displayName,
|