@docyrus/signin 0.18.1 → 0.18.2

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.
@@ -2,7 +2,7 @@ import { OAuth2Tokens } from '@docyrus/api-client';
2
2
  import { D as DocyrusAuthConfig } from '../types-BcLDyMdw.js';
3
3
  export { A as AclOperation, a as AclTargetType, b as AdaptiveCard, c as AuthMode, d as AuthSessionResult, e as AuthStatus, f as DocyrusAclRule, g as DocyrusAuthContextValue, h as DocyrusCalendarEventPayload, i as DocyrusEmailPayload, j as DocyrusPermission, k as DocyrusRole, l as DocyrusShareAdaptiveCardPayload, m as DocyrusSharePayload, n as DocyrusShareTextPayload, o as DocyrusUser, M as MsGraphAccount, p as MsGraphClient, q as MsGraphRequest, r as MsGraphRequestOptions, s as MsGraphResponse, t as MsGraphStatus, O as OpenAuthSessionFn, P as PermissionConfig, u as PermissionScope } from '../types-BcLDyMdw.js';
4
4
  export { D as DocyrusAuthContext, a as DocyrusAuthProvider, b as DocyrusAuthProviderProps, u as useDocyrusAuth, c as useDocyrusClient } from '../use-docyrus-client-C9uiHma9.js';
5
- export { A as AuthManager, D as DEFAULT_API_URL, a as DEFAULT_OAUTH_SCOPES, g as getAllRoles, b as getAllowedOperations, h as hasPermission, c as hasRole } from '../constants-BVfrHdk1.js';
5
+ export { A as AuthManager, D as DEFAULT_API_URL, a as DEFAULT_OAUTH_SCOPES, g as getAllRoles, b as getAllowedOperations, h as hasPermission, c as hasRole } from '../constants-CvMiR-RM.js';
6
6
  import 'react';
7
7
 
8
8
  /**
@@ -1108,6 +1108,8 @@ var AuthManager = class {
1108
1108
  error = null;
1109
1109
  client = null;
1110
1110
  user = null;
1111
+ /** In-flight `/v1/users/me` request, tied to the client that issued it. */
1112
+ userFetch = null;
1111
1113
  standaloneAuth = null;
1112
1114
  iframeAuth = null;
1113
1115
  guidyBridge = null;
@@ -1551,20 +1553,40 @@ var AuthManager = class {
1551
1553
  this.scheduleTokenRefresh(tokens);
1552
1554
  this.notify();
1553
1555
  if (isNewSession || !this.user) {
1554
- this.fetchUser();
1556
+ void this.fetchUser();
1555
1557
  }
1556
1558
  }
1557
- /** Fetch the current user from /v1/users/me. Silently sets user to null on failure. */
1558
- async fetchUser() {
1559
- if (!this.client) return;
1560
- try {
1561
- const response = await this.client.get("/v1/users/me");
1562
- const maybeUser = response;
1563
- this.user = maybeUser && typeof maybeUser === "object" && "id" in maybeUser && "email" in maybeUser ? maybeUser : response.data;
1564
- } catch {
1565
- this.user = null;
1566
- }
1567
- this.notify();
1559
+ /**
1560
+ * Fetch the current user from /v1/users/me. Silently sets user to null on failure.
1561
+ *
1562
+ * Concurrent calls share one request: `setAuthenticated` fetches whenever the
1563
+ * user is still missing, so a second token push that lands while the first
1564
+ * fetch is in flight (e.g. stored tokens restored on load, then the host or a
1565
+ * bridge pushing its session) would otherwise fire a duplicate request. A
1566
+ * result is dropped if the client changed meanwhile (sign-out or a new
1567
+ * session), so a stale user never overwrites the current one.
1568
+ */
1569
+ fetchUser() {
1570
+ const { client } = this;
1571
+ if (!client) return Promise.resolve();
1572
+ if (this.userFetch?.client === client) return this.userFetch.promise;
1573
+ const promise = (async () => {
1574
+ let user = null;
1575
+ try {
1576
+ const response = await client.get("/v1/users/me");
1577
+ const maybeUser = response;
1578
+ user = maybeUser && typeof maybeUser === "object" && "id" in maybeUser && "email" in maybeUser ? maybeUser : response.data;
1579
+ } catch {
1580
+ user = null;
1581
+ }
1582
+ if (this.client !== client) return;
1583
+ this.user = user;
1584
+ this.notify();
1585
+ })().finally(() => {
1586
+ if (this.userFetch?.promise === promise) this.userFetch = null;
1587
+ });
1588
+ this.userFetch = { client, promise };
1589
+ return promise;
1568
1590
  }
1569
1591
  /**
1570
1592
  * Create a RestApiClient with a custom TokenManager that proactively