@stackframe/stack 2.7.29 → 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 +10 -0
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js +45 -3
- 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 +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js +45 -3
- 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
package/CHANGELOG.md
CHANGED
|
@@ -106,6 +106,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
106
106
|
return await this._interface.listClientContactChannels(session);
|
|
107
107
|
}
|
|
108
108
|
);
|
|
109
|
+
this._anonymousSignUpInProgress = null;
|
|
109
110
|
this._memoryTokenStore = createEmptyTokenStore();
|
|
110
111
|
this._nextServerCookiesTokenStores = /* @__PURE__ */ new WeakMap();
|
|
111
112
|
this._requestTokenStores = /* @__PURE__ */ new WeakMap();
|
|
@@ -999,7 +1000,10 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
999
1000
|
async getUser(options) {
|
|
1000
1001
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1001
1002
|
const session = await this._getSession(options?.tokenStore);
|
|
1002
|
-
|
|
1003
|
+
let crud = Result.orThrow(await this._currentUserCache.getOrWait([session], "write-only"));
|
|
1004
|
+
if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists") {
|
|
1005
|
+
crud = null;
|
|
1006
|
+
}
|
|
1003
1007
|
if (crud === null) {
|
|
1004
1008
|
switch (options?.or) {
|
|
1005
1009
|
case "redirect": {
|
|
@@ -1009,7 +1013,13 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1009
1013
|
case "throw": {
|
|
1010
1014
|
throw new Error("User is not signed in but getUser was called with { or: 'throw' }");
|
|
1011
1015
|
}
|
|
1012
|
-
|
|
1016
|
+
case "anonymous": {
|
|
1017
|
+
const tokens = await this._signUpAnonymously();
|
|
1018
|
+
return await this.getUser({ tokenStore: tokens }) ?? throwErr("Something went wrong while signing up anonymously");
|
|
1019
|
+
}
|
|
1020
|
+
case void 0:
|
|
1021
|
+
case "anonymous-if-exists":
|
|
1022
|
+
case "return-null": {
|
|
1013
1023
|
return null;
|
|
1014
1024
|
}
|
|
1015
1025
|
}
|
|
@@ -1019,7 +1029,10 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1019
1029
|
useUser(options) {
|
|
1020
1030
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1021
1031
|
const session = this._useSession(options?.tokenStore);
|
|
1022
|
-
|
|
1032
|
+
let crud = useAsyncCache(this._currentUserCache, [session], "useUser()");
|
|
1033
|
+
if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists") {
|
|
1034
|
+
crud = null;
|
|
1035
|
+
}
|
|
1023
1036
|
if (crud === null) {
|
|
1024
1037
|
switch (options?.or) {
|
|
1025
1038
|
case "redirect": {
|
|
@@ -1030,7 +1043,18 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1030
1043
|
case "throw": {
|
|
1031
1044
|
throw new Error("User is not signed in but useUser was called with { or: 'throw' }");
|
|
1032
1045
|
}
|
|
1046
|
+
case "anonymous": {
|
|
1047
|
+
runAsynchronously(async () => {
|
|
1048
|
+
await this._signUpAnonymously();
|
|
1049
|
+
if (typeof window !== "undefined") {
|
|
1050
|
+
window.location.reload();
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
suspend();
|
|
1054
|
+
throw new StackAssertionError("suspend should never return");
|
|
1055
|
+
}
|
|
1033
1056
|
case void 0:
|
|
1057
|
+
case "anonymous-if-exists":
|
|
1034
1058
|
case "return-null": {
|
|
1035
1059
|
}
|
|
1036
1060
|
}
|
|
@@ -1132,6 +1156,24 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1132
1156
|
return Result.error(result.error);
|
|
1133
1157
|
}
|
|
1134
1158
|
}
|
|
1159
|
+
async _signUpAnonymously() {
|
|
1160
|
+
this._ensurePersistentTokenStore();
|
|
1161
|
+
if (!this._anonymousSignUpInProgress) {
|
|
1162
|
+
this._anonymousSignUpInProgress = (async () => {
|
|
1163
|
+
this._ensurePersistentTokenStore();
|
|
1164
|
+
const session = await this._getSession();
|
|
1165
|
+
const result = await this._interface.signUpAnonymously(session);
|
|
1166
|
+
if (result.status === "ok") {
|
|
1167
|
+
await this._signInToAccountWithTokens(result.data);
|
|
1168
|
+
} else {
|
|
1169
|
+
throw new StackAssertionError("signUpAnonymously() should never return an error");
|
|
1170
|
+
}
|
|
1171
|
+
this._anonymousSignUpInProgress = null;
|
|
1172
|
+
return result.data;
|
|
1173
|
+
})();
|
|
1174
|
+
}
|
|
1175
|
+
return await this._anonymousSignUpInProgress;
|
|
1176
|
+
}
|
|
1135
1177
|
async signInWithMagicLink(code, options) {
|
|
1136
1178
|
this._ensurePersistentTokenStore();
|
|
1137
1179
|
let result;
|