@openstax/ts-utils 1.41.2 → 1.41.3

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.
@@ -27,8 +27,7 @@ const subrequestAuthProvider = (initializer) => (configProvider) => {
27
27
  return undefined;
28
28
  }
29
29
  const user = await (0, userSubrequest_1.loadUserData)(initializer.fetch, await accountsBase(), resolvedCookieName, token);
30
- // this returns `{"error_id":null}` when the token is invalid
31
- if (user.uuid) {
30
+ if (user) {
32
31
  logger.setContext({ user: user.uuid });
33
32
  return user;
34
33
  }
@@ -1,3 +1,3 @@
1
1
  import { ApiUser } from '..';
2
2
  import { GenericFetch } from '../../../fetch';
3
- export declare const loadUserData: (fetch: GenericFetch, accountsBase: string, cookieName: string, token: string) => Promise<ApiUser>;
3
+ export declare const loadUserData: (fetch: GenericFetch, accountsBase: string, cookieName: string, token: string) => Promise<ApiUser | undefined>;
@@ -7,7 +7,9 @@ exports.loadUserData = void 0;
7
7
  const cookie_1 = __importDefault(require("cookie"));
8
8
  const loadUserData = (fetch, accountsBase, cookieName, token) => {
9
9
  const headers = { cookie: cookie_1.default.serialize(cookieName, token) };
10
+ // this returns `{"error_id":null}` when the token is invalid
10
11
  return fetch(accountsBase.replace(/\/+$/, '') + '/api/user', { headers })
11
- .then(response => response.json());
12
+ .then(response => response.json())
13
+ .then(data => ('error_id' in data ? undefined : data));
12
14
  };
13
15
  exports.loadUserData = loadUserData;