@stackframe/stack 2.7.28 → 2.7.30
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 +20 -0
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js +52 -8
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/common.js +6 -6
- package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +27 -4
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
- package/dist/esm/lib/stack-app/common.js.map +1 -1
- package/dist/esm/providers/stack-provider.js +1 -1
- package/dist/esm/providers/stack-provider.js.map +1 -1
- package/dist/index.d.mts +17 -3
- package/dist/index.d.ts +17 -3
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js +52 -8
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/common.js +6 -6
- package/dist/lib/stack-app/apps/implementations/common.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js +26 -3
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
- package/dist/lib/stack-app/common.js.map +1 -1
- package/dist/providers/stack-provider.js +1 -1
- package/dist/providers/stack-provider.js.map +1 -1
- package/package.json +4 -4
|
@@ -140,6 +140,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
140
140
|
return await this._interface.listClientContactChannels(session);
|
|
141
141
|
}
|
|
142
142
|
);
|
|
143
|
+
this._anonymousSignUpInProgress = null;
|
|
143
144
|
this._memoryTokenStore = (0, import_common2.createEmptyTokenStore)();
|
|
144
145
|
this._nextServerCookiesTokenStores = /* @__PURE__ */ new WeakMap();
|
|
145
146
|
this._requestTokenStores = /* @__PURE__ */ new WeakMap();
|
|
@@ -1033,7 +1034,10 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1033
1034
|
async getUser(options) {
|
|
1034
1035
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1035
1036
|
const session = await this._getSession(options?.tokenStore);
|
|
1036
|
-
|
|
1037
|
+
let crud = import_results.Result.orThrow(await this._currentUserCache.getOrWait([session], "write-only"));
|
|
1038
|
+
if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists") {
|
|
1039
|
+
crud = null;
|
|
1040
|
+
}
|
|
1037
1041
|
if (crud === null) {
|
|
1038
1042
|
switch (options?.or) {
|
|
1039
1043
|
case "redirect": {
|
|
@@ -1043,7 +1047,13 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1043
1047
|
case "throw": {
|
|
1044
1048
|
throw new Error("User is not signed in but getUser was called with { or: 'throw' }");
|
|
1045
1049
|
}
|
|
1046
|
-
|
|
1050
|
+
case "anonymous": {
|
|
1051
|
+
const tokens = await this._signUpAnonymously();
|
|
1052
|
+
return await this.getUser({ tokenStore: tokens }) ?? (0, import_errors.throwErr)("Something went wrong while signing up anonymously");
|
|
1053
|
+
}
|
|
1054
|
+
case void 0:
|
|
1055
|
+
case "anonymous-if-exists":
|
|
1056
|
+
case "return-null": {
|
|
1047
1057
|
return null;
|
|
1048
1058
|
}
|
|
1049
1059
|
}
|
|
@@ -1053,7 +1063,10 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1053
1063
|
useUser(options) {
|
|
1054
1064
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1055
1065
|
const session = this._useSession(options?.tokenStore);
|
|
1056
|
-
|
|
1066
|
+
let crud = (0, import_common3.useAsyncCache)(this._currentUserCache, [session], "useUser()");
|
|
1067
|
+
if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists") {
|
|
1068
|
+
crud = null;
|
|
1069
|
+
}
|
|
1057
1070
|
if (crud === null) {
|
|
1058
1071
|
switch (options?.or) {
|
|
1059
1072
|
case "redirect": {
|
|
@@ -1064,7 +1077,18 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1064
1077
|
case "throw": {
|
|
1065
1078
|
throw new Error("User is not signed in but useUser was called with { or: 'throw' }");
|
|
1066
1079
|
}
|
|
1080
|
+
case "anonymous": {
|
|
1081
|
+
(0, import_promises.runAsynchronously)(async () => {
|
|
1082
|
+
await this._signUpAnonymously();
|
|
1083
|
+
if (typeof window !== "undefined") {
|
|
1084
|
+
window.location.reload();
|
|
1085
|
+
}
|
|
1086
|
+
});
|
|
1087
|
+
(0, import_react.suspend)();
|
|
1088
|
+
throw new import_errors.StackAssertionError("suspend should never return");
|
|
1089
|
+
}
|
|
1067
1090
|
case void 0:
|
|
1091
|
+
case "anonymous-if-exists":
|
|
1068
1092
|
case "return-null": {
|
|
1069
1093
|
}
|
|
1070
1094
|
}
|
|
@@ -1166,7 +1190,25 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1166
1190
|
return import_results.Result.error(result.error);
|
|
1167
1191
|
}
|
|
1168
1192
|
}
|
|
1169
|
-
async
|
|
1193
|
+
async _signUpAnonymously() {
|
|
1194
|
+
this._ensurePersistentTokenStore();
|
|
1195
|
+
if (!this._anonymousSignUpInProgress) {
|
|
1196
|
+
this._anonymousSignUpInProgress = (async () => {
|
|
1197
|
+
this._ensurePersistentTokenStore();
|
|
1198
|
+
const session = await this._getSession();
|
|
1199
|
+
const result = await this._interface.signUpAnonymously(session);
|
|
1200
|
+
if (result.status === "ok") {
|
|
1201
|
+
await this._signInToAccountWithTokens(result.data);
|
|
1202
|
+
} else {
|
|
1203
|
+
throw new import_errors.StackAssertionError("signUpAnonymously() should never return an error");
|
|
1204
|
+
}
|
|
1205
|
+
this._anonymousSignUpInProgress = null;
|
|
1206
|
+
return result.data;
|
|
1207
|
+
})();
|
|
1208
|
+
}
|
|
1209
|
+
return await this._anonymousSignUpInProgress;
|
|
1210
|
+
}
|
|
1211
|
+
async signInWithMagicLink(code, options) {
|
|
1170
1212
|
this._ensurePersistentTokenStore();
|
|
1171
1213
|
let result;
|
|
1172
1214
|
try {
|
|
@@ -1181,10 +1223,12 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1181
1223
|
}
|
|
1182
1224
|
if (result.status === "ok") {
|
|
1183
1225
|
await this._signInToAccountWithTokens(result.data);
|
|
1184
|
-
if (
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1226
|
+
if (!options?.noRedirect) {
|
|
1227
|
+
if (result.data.newUser) {
|
|
1228
|
+
await this.redirectToAfterSignUp({ replace: true });
|
|
1229
|
+
} else {
|
|
1230
|
+
await this.redirectToAfterSignIn({ replace: true });
|
|
1231
|
+
}
|
|
1188
1232
|
}
|
|
1189
1233
|
return import_results.Result.ok(void 0);
|
|
1190
1234
|
} else {
|