@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.
@@ -615,7 +615,7 @@ type StackServerApp<HasTokenStore extends boolean = boolean, ProjectId extends s
615
615
  or: 'throw';
616
616
  }): Promise<ProjectCurrentServerUser<ProjectId>>;
617
617
  getUser(options?: GetUserOptions<HasTokenStore>): Promise<ProjectCurrentServerUser<ProjectId> | null>;
618
- } & AsyncStoreProperty<"users", [], ServerUser[], true> & AsyncStoreProperty<"team", [id: string], ServerTeam | null, false> & AsyncStoreProperty<"teams", [], ServerTeam[], true> & StackClientApp<HasTokenStore, ProjectId>);
618
+ } & AsyncStoreProperty<"user", [id: string], ServerUser | null, false> & AsyncStoreProperty<"users", [], ServerUser[], true> & AsyncStoreProperty<"team", [id: string], ServerTeam | null, false> & AsyncStoreProperty<"teams", [], ServerTeam[], true> & StackClientApp<HasTokenStore, ProjectId>);
619
619
  declare const StackServerApp: StackServerAppConstructor;
620
620
  type StackAdminAppConstructor = {
621
621
  new <HasTokenStore extends boolean, ProjectId extends string>(options: StackAdminAppConstructorOptions<HasTokenStore, ProjectId>): StackAdminApp<HasTokenStore, ProjectId>;
@@ -615,7 +615,7 @@ type StackServerApp<HasTokenStore extends boolean = boolean, ProjectId extends s
615
615
  or: 'throw';
616
616
  }): Promise<ProjectCurrentServerUser<ProjectId>>;
617
617
  getUser(options?: GetUserOptions<HasTokenStore>): Promise<ProjectCurrentServerUser<ProjectId> | null>;
618
- } & AsyncStoreProperty<"users", [], ServerUser[], true> & AsyncStoreProperty<"team", [id: string], ServerTeam | null, false> & AsyncStoreProperty<"teams", [], ServerTeam[], true> & StackClientApp<HasTokenStore, ProjectId>);
618
+ } & AsyncStoreProperty<"user", [id: string], ServerUser | null, false> & AsyncStoreProperty<"users", [], ServerUser[], true> & AsyncStoreProperty<"team", [id: string], ServerTeam | null, false> & AsyncStoreProperty<"teams", [], ServerTeam[], true> & StackClientApp<HasTokenStore, ProjectId>);
619
619
  declare const StackServerApp: StackServerAppConstructor;
620
620
  type StackAdminAppConstructor = {
621
621
  new <HasTokenStore extends boolean, ProjectId extends string>(options: StackAdminAppConstructorOptions<HasTokenStore, ProjectId>): StackAdminApp<HasTokenStore, ProjectId>;
@@ -63,7 +63,7 @@ var import_url = require("../utils/url");
63
63
  var import_auth = require("./auth");
64
64
  var import_cookie = require("./cookie");
65
65
  var NextNavigation = (0, import_compile_time.scrambleDuringCompileTime)(NextNavigationUnscrambled);
66
- var clientVersion = "js @stackframe/stack@2.5.23";
66
+ var clientVersion = "js @stackframe/stack@2.5.24";
67
67
  function getUrls(partial) {
68
68
  const handler = partial.handler ?? "/handler";
69
69
  const home = partial.home ?? "/";
@@ -1505,24 +1505,29 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1505
1505
  return this._serverUserFromCrud(crud);
1506
1506
  }
1507
1507
  async getUser(options) {
1508
- this._ensurePersistentTokenStore(options?.tokenStore);
1509
- const session = this._getSession(options?.tokenStore);
1510
- const crud = await this._currentServerUserCache.getOrWait([session], "write-only");
1511
- if (crud === null) {
1512
- switch (options?.or) {
1513
- case "redirect": {
1514
- await this.redirectToSignIn({ replace: true });
1515
- break;
1516
- }
1517
- case "throw": {
1518
- throw new Error("User is not signed in but getUser was called with { or: 'throw' }");
1519
- }
1520
- default: {
1521
- return null;
1508
+ if (typeof options === "string") {
1509
+ const allUsers = await this.listUsers();
1510
+ return allUsers.find((u) => u.id === options) ?? null;
1511
+ } else {
1512
+ this._ensurePersistentTokenStore(options?.tokenStore);
1513
+ const session = this._getSession(options?.tokenStore);
1514
+ const crud = await this._currentServerUserCache.getOrWait([session], "write-only");
1515
+ if (crud === null) {
1516
+ switch (options?.or) {
1517
+ case "redirect": {
1518
+ await this.redirectToSignIn({ replace: true });
1519
+ break;
1520
+ }
1521
+ case "throw": {
1522
+ throw new Error("User is not signed in but getUser was called with { or: 'throw' }");
1523
+ }
1524
+ default: {
1525
+ return null;
1526
+ }
1522
1527
  }
1523
1528
  }
1529
+ return crud && this._currentUserFromCrud(crud, session);
1524
1530
  }
1525
- return crud && this._currentUserFromCrud(crud, session);
1526
1531
  }
1527
1532
  async getServerUser() {
1528
1533
  console.warn("stackServerApp.getServerUser is deprecated; use stackServerApp.getUser instead");
@@ -1533,28 +1538,33 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1533
1538
  return crud && this._serverUserFromCrud(crud);
1534
1539
  }
1535
1540
  useUser(options) {
1536
- this._ensurePersistentTokenStore(options?.tokenStore);
1537
- const router = NextNavigation.useRouter();
1538
- const session = this._getSession(options?.tokenStore);
1539
- const crud = useAsyncCache(this._currentServerUserCache, [session], "useUser()");
1540
- if (crud === null) {
1541
- switch (options?.or) {
1542
- case "redirect": {
1543
- (0, import_promises.runAsynchronously)(this.redirectToSignIn({ replace: true }));
1544
- (0, import_react.suspend)();
1545
- throw new import_errors.StackAssertionError("suspend should never return");
1546
- }
1547
- case "throw": {
1548
- throw new Error("User is not signed in but useUser was called with { or: 'throw' }");
1549
- }
1550
- case void 0:
1551
- case "return-null": {
1541
+ if (typeof options === "string") {
1542
+ const users = this.useUsers();
1543
+ return users.find((u) => u.id === options) ?? null;
1544
+ } else {
1545
+ this._ensurePersistentTokenStore(options?.tokenStore);
1546
+ const router = NextNavigation.useRouter();
1547
+ const session = this._getSession(options?.tokenStore);
1548
+ const crud = useAsyncCache(this._currentServerUserCache, [session], "useUser()");
1549
+ if (crud === null) {
1550
+ switch (options?.or) {
1551
+ case "redirect": {
1552
+ (0, import_promises.runAsynchronously)(this.redirectToSignIn({ replace: true }));
1553
+ (0, import_react.suspend)();
1554
+ throw new import_errors.StackAssertionError("suspend should never return");
1555
+ }
1556
+ case "throw": {
1557
+ throw new Error("User is not signed in but useUser was called with { or: 'throw' }");
1558
+ }
1559
+ case void 0:
1560
+ case "return-null": {
1561
+ }
1552
1562
  }
1553
1563
  }
1564
+ return (0, import_react2.useMemo)(() => {
1565
+ return crud && this._currentUserFromCrud(crud, session);
1566
+ }, [crud, session, options?.or]);
1554
1567
  }
1555
- return (0, import_react2.useMemo)(() => {
1556
- return crud && this._currentUserFromCrud(crud, session);
1557
- }, [crud, session, options?.or]);
1558
1568
  }
1559
1569
  useUserById(userId) {
1560
1570
  const crud = useAsyncCache(this._serverUserCache, [userId], "useUserById()");