@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.
Files changed (26) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js +45 -3
  3. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
  4. package/dist/esm/lib/stack-app/apps/implementations/common.js +6 -6
  5. package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -1
  6. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +27 -4
  7. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
  8. package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
  9. package/dist/esm/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
  10. package/dist/esm/lib/stack-app/common.js.map +1 -1
  11. package/dist/esm/providers/stack-provider.js +1 -1
  12. package/dist/esm/providers/stack-provider.js.map +1 -1
  13. package/dist/index.d.mts +13 -1
  14. package/dist/index.d.ts +13 -1
  15. package/dist/lib/stack-app/apps/implementations/client-app-impl.js +45 -3
  16. package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
  17. package/dist/lib/stack-app/apps/implementations/common.js +6 -6
  18. package/dist/lib/stack-app/apps/implementations/common.js.map +1 -1
  19. package/dist/lib/stack-app/apps/implementations/server-app-impl.js +26 -3
  20. package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
  21. package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
  22. package/dist/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
  23. package/dist/lib/stack-app/common.js.map +1 -1
  24. package/dist/providers/stack-provider.js +1 -1
  25. package/dist/providers/stack-provider.js.map +1 -1
  26. 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
- const crud = import_results.Result.orThrow(await this._currentUserCache.getOrWait([session], "write-only"));
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
- default: {
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
- const crud = (0, import_common3.useAsyncCache)(this._currentUserCache, [session], "useUser()");
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,6 +1190,24 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1166
1190
  return import_results.Result.error(result.error);
1167
1191
  }
1168
1192
  }
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
+ }
1169
1211
  async signInWithMagicLink(code, options) {
1170
1212
  this._ensurePersistentTokenStore();
1171
1213
  let result;