@zoreal/oauth2-react 0.2.22 → 0.2.23

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/index.cjs CHANGED
@@ -42,7 +42,7 @@ var import_react2 = require("react");
42
42
 
43
43
  // src/wire.ts
44
44
  var WIRE_VERSION = 1;
45
- var SDK_VERSION = "0.2.22";
45
+ var SDK_VERSION = "0.2.23";
46
46
  var DEFAULT_ISSUER = "https://id.zoreal.com";
47
47
  var POLL_INTERVAL_MS = 2e3;
48
48
  var POLL_INTERVAL_ENROLLING_MS = 5e3;
@@ -1786,6 +1786,30 @@ function markReturnDone(requestId) {
1786
1786
  function isReturnDone(requestId) {
1787
1787
  return storage()?.getItem(DONE + requestId) !== null && storage()?.getItem(DONE + requestId) !== void 0;
1788
1788
  }
1789
+ function visibleOrDone(requestId, signal) {
1790
+ if (typeof document === "undefined" || document.visibilityState !== "hidden") {
1791
+ return Promise.resolve(!isReturnDone(requestId));
1792
+ }
1793
+ return new Promise((resolve) => {
1794
+ const finish = (value) => {
1795
+ document.removeEventListener("visibilitychange", onVisible);
1796
+ window.removeEventListener("storage", onStorage);
1797
+ signal?.removeEventListener("abort", onAbort);
1798
+ resolve(value);
1799
+ };
1800
+ const onVisible = () => {
1801
+ if (document.visibilityState !== "hidden") finish(!isReturnDone(requestId));
1802
+ };
1803
+ const onStorage = () => {
1804
+ if (isReturnDone(requestId)) finish(false);
1805
+ };
1806
+ const onAbort = () => finish(false);
1807
+ document.addEventListener("visibilitychange", onVisible);
1808
+ window.addEventListener("storage", onStorage);
1809
+ signal?.addEventListener("abort", onAbort, { once: true });
1810
+ if (isReturnDone(requestId)) finish(false);
1811
+ });
1812
+ }
1789
1813
  function returnToUrl() {
1790
1814
  if (typeof window === "undefined") return void 0;
1791
1815
  const { href } = window.location;
@@ -2348,7 +2372,7 @@ function useZorealFlow(options) {
2348
2372
  controller.signal,
2349
2373
  { tolerateUnknownUntil: Date.now() + 15e3 }
2350
2374
  );
2351
- if (isReturnDone(requestId)) {
2375
+ if (!await visibleOrDone(requestId, controller.signal)) {
2352
2376
  throw new DOMException("aborted", "AbortError");
2353
2377
  }
2354
2378
  } else {