@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.
package/dist/vue/index.js CHANGED
@@ -1105,6 +1105,8 @@ var AuthManager = class {
1105
1105
  error = null;
1106
1106
  client = null;
1107
1107
  user = null;
1108
+ /** In-flight `/v1/users/me` request, tied to the client that issued it. */
1109
+ userFetch = null;
1108
1110
  standaloneAuth = null;
1109
1111
  iframeAuth = null;
1110
1112
  guidyBridge = null;
@@ -1548,20 +1550,40 @@ var AuthManager = class {
1548
1550
  this.scheduleTokenRefresh(tokens);
1549
1551
  this.notify();
1550
1552
  if (isNewSession || !this.user) {
1551
- this.fetchUser();
1553
+ void this.fetchUser();
1552
1554
  }
1553
1555
  }
1554
- /** Fetch the current user from /v1/users/me. Silently sets user to null on failure. */
1555
- async fetchUser() {
1556
- if (!this.client) return;
1557
- try {
1558
- const response = await this.client.get("/v1/users/me");
1559
- const maybeUser = response;
1560
- this.user = maybeUser && typeof maybeUser === "object" && "id" in maybeUser && "email" in maybeUser ? maybeUser : response.data;
1561
- } catch {
1562
- this.user = null;
1563
- }
1564
- this.notify();
1556
+ /**
1557
+ * Fetch the current user from /v1/users/me. Silently sets user to null on failure.
1558
+ *
1559
+ * Concurrent calls share one request: `setAuthenticated` fetches whenever the
1560
+ * user is still missing, so a second token push that lands while the first
1561
+ * fetch is in flight (e.g. stored tokens restored on load, then the host or a
1562
+ * bridge pushing its session) would otherwise fire a duplicate request. A
1563
+ * result is dropped if the client changed meanwhile (sign-out or a new
1564
+ * session), so a stale user never overwrites the current one.
1565
+ */
1566
+ fetchUser() {
1567
+ const { client } = this;
1568
+ if (!client) return Promise.resolve();
1569
+ if (this.userFetch?.client === client) return this.userFetch.promise;
1570
+ const promise = (async () => {
1571
+ let user = null;
1572
+ try {
1573
+ const response = await client.get("/v1/users/me");
1574
+ const maybeUser = response;
1575
+ user = maybeUser && typeof maybeUser === "object" && "id" in maybeUser && "email" in maybeUser ? maybeUser : response.data;
1576
+ } catch {
1577
+ user = null;
1578
+ }
1579
+ if (this.client !== client) return;
1580
+ this.user = user;
1581
+ this.notify();
1582
+ })().finally(() => {
1583
+ if (this.userFetch?.promise === promise) this.userFetch = null;
1584
+ });
1585
+ this.userFetch = { client, promise };
1586
+ return promise;
1565
1587
  }
1566
1588
  /**
1567
1589
  * Create a RestApiClient with a custom TokenManager that proactively