@stackframe/react 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 +3 -3
|
@@ -135,6 +135,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
135
135
|
return await this._interface.listClientContactChannels(session);
|
|
136
136
|
}
|
|
137
137
|
);
|
|
138
|
+
this._anonymousSignUpInProgress = null;
|
|
138
139
|
this._memoryTokenStore = (0, import_common2.createEmptyTokenStore)();
|
|
139
140
|
this._nextServerCookiesTokenStores = /* @__PURE__ */ new WeakMap();
|
|
140
141
|
this._requestTokenStores = /* @__PURE__ */ new WeakMap();
|
|
@@ -1021,7 +1022,10 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1021
1022
|
async getUser(options) {
|
|
1022
1023
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1023
1024
|
const session = await this._getSession(options?.tokenStore);
|
|
1024
|
-
|
|
1025
|
+
let crud = import_results.Result.orThrow(await this._currentUserCache.getOrWait([session], "write-only"));
|
|
1026
|
+
if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists") {
|
|
1027
|
+
crud = null;
|
|
1028
|
+
}
|
|
1025
1029
|
if (crud === null) {
|
|
1026
1030
|
switch (options?.or) {
|
|
1027
1031
|
case "redirect": {
|
|
@@ -1031,7 +1035,13 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1031
1035
|
case "throw": {
|
|
1032
1036
|
throw new Error("User is not signed in but getUser was called with { or: 'throw' }");
|
|
1033
1037
|
}
|
|
1034
|
-
|
|
1038
|
+
case "anonymous": {
|
|
1039
|
+
const tokens = await this._signUpAnonymously();
|
|
1040
|
+
return await this.getUser({ tokenStore: tokens }) ?? (0, import_errors.throwErr)("Something went wrong while signing up anonymously");
|
|
1041
|
+
}
|
|
1042
|
+
case void 0:
|
|
1043
|
+
case "anonymous-if-exists":
|
|
1044
|
+
case "return-null": {
|
|
1035
1045
|
return null;
|
|
1036
1046
|
}
|
|
1037
1047
|
}
|
|
@@ -1041,7 +1051,10 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1041
1051
|
useUser(options) {
|
|
1042
1052
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1043
1053
|
const session = this._useSession(options?.tokenStore);
|
|
1044
|
-
|
|
1054
|
+
let crud = (0, import_common3.useAsyncCache)(this._currentUserCache, [session], "useUser()");
|
|
1055
|
+
if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists") {
|
|
1056
|
+
crud = null;
|
|
1057
|
+
}
|
|
1045
1058
|
if (crud === null) {
|
|
1046
1059
|
switch (options?.or) {
|
|
1047
1060
|
case "redirect": {
|
|
@@ -1052,7 +1065,18 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1052
1065
|
case "throw": {
|
|
1053
1066
|
throw new Error("User is not signed in but useUser was called with { or: 'throw' }");
|
|
1054
1067
|
}
|
|
1068
|
+
case "anonymous": {
|
|
1069
|
+
(0, import_promises.runAsynchronously)(async () => {
|
|
1070
|
+
await this._signUpAnonymously();
|
|
1071
|
+
if (typeof window !== "undefined") {
|
|
1072
|
+
window.location.reload();
|
|
1073
|
+
}
|
|
1074
|
+
});
|
|
1075
|
+
(0, import_react.suspend)();
|
|
1076
|
+
throw new import_errors.StackAssertionError("suspend should never return");
|
|
1077
|
+
}
|
|
1055
1078
|
case void 0:
|
|
1079
|
+
case "anonymous-if-exists":
|
|
1056
1080
|
case "return-null": {
|
|
1057
1081
|
}
|
|
1058
1082
|
}
|
|
@@ -1154,7 +1178,25 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1154
1178
|
return import_results.Result.error(result.error);
|
|
1155
1179
|
}
|
|
1156
1180
|
}
|
|
1157
|
-
async
|
|
1181
|
+
async _signUpAnonymously() {
|
|
1182
|
+
this._ensurePersistentTokenStore();
|
|
1183
|
+
if (!this._anonymousSignUpInProgress) {
|
|
1184
|
+
this._anonymousSignUpInProgress = (async () => {
|
|
1185
|
+
this._ensurePersistentTokenStore();
|
|
1186
|
+
const session = await this._getSession();
|
|
1187
|
+
const result = await this._interface.signUpAnonymously(session);
|
|
1188
|
+
if (result.status === "ok") {
|
|
1189
|
+
await this._signInToAccountWithTokens(result.data);
|
|
1190
|
+
} else {
|
|
1191
|
+
throw new import_errors.StackAssertionError("signUpAnonymously() should never return an error");
|
|
1192
|
+
}
|
|
1193
|
+
this._anonymousSignUpInProgress = null;
|
|
1194
|
+
return result.data;
|
|
1195
|
+
})();
|
|
1196
|
+
}
|
|
1197
|
+
return await this._anonymousSignUpInProgress;
|
|
1198
|
+
}
|
|
1199
|
+
async signInWithMagicLink(code, options) {
|
|
1158
1200
|
this._ensurePersistentTokenStore();
|
|
1159
1201
|
let result;
|
|
1160
1202
|
try {
|
|
@@ -1169,10 +1211,12 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1169
1211
|
}
|
|
1170
1212
|
if (result.status === "ok") {
|
|
1171
1213
|
await this._signInToAccountWithTokens(result.data);
|
|
1172
|
-
if (
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1214
|
+
if (!options?.noRedirect) {
|
|
1215
|
+
if (result.data.newUser) {
|
|
1216
|
+
await this.redirectToAfterSignUp({ replace: true });
|
|
1217
|
+
} else {
|
|
1218
|
+
await this.redirectToAfterSignIn({ replace: true });
|
|
1219
|
+
}
|
|
1176
1220
|
}
|
|
1177
1221
|
return import_results.Result.ok(void 0);
|
|
1178
1222
|
} else {
|