@stackframe/stack 2.5.23 → 2.5.24

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 CHANGED
@@ -1,5 +1,15 @@
1
1
  # @stackframe/stack
2
2
 
3
+ ## 2.5.24
4
+
5
+ ### Patch Changes
6
+
7
+ - Various bugfixes
8
+ - Updated dependencies
9
+ - @stackframe/stack-shared@2.5.24
10
+ - @stackframe/stack-ui@2.5.24
11
+ - @stackframe/stack-sc@2.5.24
12
+
3
13
  ## 2.5.23
4
14
 
5
15
  ### Patch Changes
@@ -24,7 +24,7 @@ import { constructRedirectUrl } from "../utils/url";
24
24
  import { addNewOAuthProviderOrScope, callOAuthCallback, signInWithOAuth } from "./auth";
25
25
  import { deleteCookie, getCookie, setOrDeleteCookie } from "./cookie";
26
26
  var NextNavigation = scrambleDuringCompileTime(NextNavigationUnscrambled);
27
- var clientVersion = "js @stackframe/stack@2.5.23";
27
+ var clientVersion = "js @stackframe/stack@2.5.24";
28
28
  function getUrls(partial) {
29
29
  const handler = partial.handler ?? "/handler";
30
30
  const home = partial.home ?? "/";
@@ -1466,24 +1466,29 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1466
1466
  return this._serverUserFromCrud(crud);
1467
1467
  }
1468
1468
  async getUser(options) {
1469
- this._ensurePersistentTokenStore(options?.tokenStore);
1470
- const session = this._getSession(options?.tokenStore);
1471
- const crud = await this._currentServerUserCache.getOrWait([session], "write-only");
1472
- if (crud === null) {
1473
- switch (options?.or) {
1474
- case "redirect": {
1475
- await this.redirectToSignIn({ replace: true });
1476
- break;
1477
- }
1478
- case "throw": {
1479
- throw new Error("User is not signed in but getUser was called with { or: 'throw' }");
1480
- }
1481
- default: {
1482
- return null;
1469
+ if (typeof options === "string") {
1470
+ const allUsers = await this.listUsers();
1471
+ return allUsers.find((u) => u.id === options) ?? null;
1472
+ } else {
1473
+ this._ensurePersistentTokenStore(options?.tokenStore);
1474
+ const session = this._getSession(options?.tokenStore);
1475
+ const crud = await this._currentServerUserCache.getOrWait([session], "write-only");
1476
+ if (crud === null) {
1477
+ switch (options?.or) {
1478
+ case "redirect": {
1479
+ await this.redirectToSignIn({ replace: true });
1480
+ break;
1481
+ }
1482
+ case "throw": {
1483
+ throw new Error("User is not signed in but getUser was called with { or: 'throw' }");
1484
+ }
1485
+ default: {
1486
+ return null;
1487
+ }
1483
1488
  }
1484
1489
  }
1490
+ return crud && this._currentUserFromCrud(crud, session);
1485
1491
  }
1486
- return crud && this._currentUserFromCrud(crud, session);
1487
1492
  }
1488
1493
  async getServerUser() {
1489
1494
  console.warn("stackServerApp.getServerUser is deprecated; use stackServerApp.getUser instead");
@@ -1494,28 +1499,33 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1494
1499
  return crud && this._serverUserFromCrud(crud);
1495
1500
  }
1496
1501
  useUser(options) {
1497
- this._ensurePersistentTokenStore(options?.tokenStore);
1498
- const router = NextNavigation.useRouter();
1499
- const session = this._getSession(options?.tokenStore);
1500
- const crud = useAsyncCache(this._currentServerUserCache, [session], "useUser()");
1501
- if (crud === null) {
1502
- switch (options?.or) {
1503
- case "redirect": {
1504
- runAsynchronously(this.redirectToSignIn({ replace: true }));
1505
- suspend();
1506
- throw new StackAssertionError("suspend should never return");
1507
- }
1508
- case "throw": {
1509
- throw new Error("User is not signed in but useUser was called with { or: 'throw' }");
1510
- }
1511
- case void 0:
1512
- case "return-null": {
1502
+ if (typeof options === "string") {
1503
+ const users = this.useUsers();
1504
+ return users.find((u) => u.id === options) ?? null;
1505
+ } else {
1506
+ this._ensurePersistentTokenStore(options?.tokenStore);
1507
+ const router = NextNavigation.useRouter();
1508
+ const session = this._getSession(options?.tokenStore);
1509
+ const crud = useAsyncCache(this._currentServerUserCache, [session], "useUser()");
1510
+ if (crud === null) {
1511
+ switch (options?.or) {
1512
+ case "redirect": {
1513
+ runAsynchronously(this.redirectToSignIn({ replace: true }));
1514
+ suspend();
1515
+ throw new StackAssertionError("suspend should never return");
1516
+ }
1517
+ case "throw": {
1518
+ throw new Error("User is not signed in but useUser was called with { or: 'throw' }");
1519
+ }
1520
+ case void 0:
1521
+ case "return-null": {
1522
+ }
1513
1523
  }
1514
1524
  }
1525
+ return useMemo(() => {
1526
+ return crud && this._currentUserFromCrud(crud, session);
1527
+ }, [crud, session, options?.or]);
1515
1528
  }
1516
- return useMemo(() => {
1517
- return crud && this._currentUserFromCrud(crud, session);
1518
- }, [crud, session, options?.or]);
1519
1529
  }
1520
1530
  useUserById(userId) {
1521
1531
  const crud = useAsyncCache(this._serverUserCache, [userId], "useUserById()");