@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.js CHANGED
@@ -5,7 +5,7 @@ import { createContext, useContext, useMemo, useState as useState2 } from "react
5
5
 
6
6
  // src/wire.ts
7
7
  var WIRE_VERSION = 1;
8
- var SDK_VERSION = "0.2.22";
8
+ var SDK_VERSION = "0.2.23";
9
9
  var DEFAULT_ISSUER = "https://id.zoreal.com";
10
10
  var POLL_INTERVAL_MS = 2e3;
11
11
  var POLL_INTERVAL_ENROLLING_MS = 5e3;
@@ -1749,6 +1749,30 @@ function markReturnDone(requestId) {
1749
1749
  function isReturnDone(requestId) {
1750
1750
  return storage()?.getItem(DONE + requestId) !== null && storage()?.getItem(DONE + requestId) !== void 0;
1751
1751
  }
1752
+ function visibleOrDone(requestId, signal) {
1753
+ if (typeof document === "undefined" || document.visibilityState !== "hidden") {
1754
+ return Promise.resolve(!isReturnDone(requestId));
1755
+ }
1756
+ return new Promise((resolve) => {
1757
+ const finish = (value) => {
1758
+ document.removeEventListener("visibilitychange", onVisible);
1759
+ window.removeEventListener("storage", onStorage);
1760
+ signal?.removeEventListener("abort", onAbort);
1761
+ resolve(value);
1762
+ };
1763
+ const onVisible = () => {
1764
+ if (document.visibilityState !== "hidden") finish(!isReturnDone(requestId));
1765
+ };
1766
+ const onStorage = () => {
1767
+ if (isReturnDone(requestId)) finish(false);
1768
+ };
1769
+ const onAbort = () => finish(false);
1770
+ document.addEventListener("visibilitychange", onVisible);
1771
+ window.addEventListener("storage", onStorage);
1772
+ signal?.addEventListener("abort", onAbort, { once: true });
1773
+ if (isReturnDone(requestId)) finish(false);
1774
+ });
1775
+ }
1752
1776
  function returnToUrl() {
1753
1777
  if (typeof window === "undefined") return void 0;
1754
1778
  const { href } = window.location;
@@ -2311,7 +2335,7 @@ function useZorealFlow(options) {
2311
2335
  controller.signal,
2312
2336
  { tolerateUnknownUntil: Date.now() + 15e3 }
2313
2337
  );
2314
- if (isReturnDone(requestId)) {
2338
+ if (!await visibleOrDone(requestId, controller.signal)) {
2315
2339
  throw new DOMException("aborted", "AbortError");
2316
2340
  }
2317
2341
  } else {