@huaqiu/dsh-auth 0.7.8 → 0.7.9

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/lib/client.js CHANGED
@@ -1067,6 +1067,17 @@ window.__ModuleLoader__.load({
1067
1067
  let hostSession = null;
1068
1068
  let hostSessionLoaded = false;
1069
1069
  /**
1070
+ * The host login trigger in flight. In host mode `auth.login()` POSTs to the
1071
+ * node half, which asks EDA (KiCad) to open its modal dialog and answers only
1072
+ * once the user dismisses it. Several surfaces call this (sidebar entry, HIT
1073
+ * cards, a click burst from an impatient user), so it is single-flighted:
1074
+ * each extra POST would occupy one of the webview's few connections to DSH
1075
+ * for the whole dialog, and once that pool is exhausted the next click never
1076
+ * reaches the host — which is what "the login button stopped opening the
1077
+ * dialog" looks like from the outside.
1078
+ */
1079
+ let inflightLogin = null;
1080
+ /**
1070
1081
  * Why the last host-session resolution failed, if it did. Transport errors
1071
1082
  * must NOT masquerade as a healthy `signed-out`: the dialog opener surfaces
1072
1083
  * them as a rejection so callers can show retry copy instead of "sign in".
@@ -1148,12 +1159,17 @@ window.__ModuleLoader__.load({
1148
1159
  },
1149
1160
  login: async (options) => {
1150
1161
  if (hostMode) {
1151
- const prevToken = hostSession?.token;
1152
- await transport.triggerLogin();
1153
- hostSessionLoaded = false;
1154
- await resolveHost();
1155
- if (hostSession?.token !== prevToken) emit(hostSession);
1156
- return;
1162
+ if (inflightLogin !== null) return inflightLogin;
1163
+ inflightLogin = (async () => {
1164
+ const prevToken = hostSession?.token;
1165
+ await transport.triggerLogin();
1166
+ hostSessionLoaded = false;
1167
+ await resolveHost();
1168
+ if (hostSession?.token !== prevToken) emit(hostSession);
1169
+ })().finally(() => {
1170
+ inflightLogin = null;
1171
+ });
1172
+ return inflightLogin;
1157
1173
  }
1158
1174
  openIframe(options ?? {});
1159
1175
  },
@@ -2244,7 +2260,7 @@ window.__ModuleLoader__.load({
2244
2260
  auth.login({
2245
2261
  lang: locale,
2246
2262
  theme: dark ? "dark" : "light"
2247
- });
2263
+ }).catch(() => {});
2248
2264
  return;
2249
2265
  }
2250
2266
  setMenuOpen((open) => !open);