@authon/js 0.1.8 → 0.1.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/dist/index.js +29 -15
- package/dist/index.mjs +29 -15
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -606,24 +606,38 @@ var Authon = class {
|
|
|
606
606
|
`width=${width},height=${height},left=${left},top=${top},toolbar=no,menubar=no`
|
|
607
607
|
);
|
|
608
608
|
let callbackReceived = false;
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
609
|
+
let cleaned = false;
|
|
610
|
+
const cleanup = () => {
|
|
611
|
+
if (cleaned) return;
|
|
612
|
+
cleaned = true;
|
|
613
|
+
window.removeEventListener("message", handler);
|
|
614
|
+
window.removeEventListener("focus", focusHandler);
|
|
615
|
+
if (maxTimer) clearTimeout(maxTimer);
|
|
616
|
+
};
|
|
617
|
+
const focusHandler = () => {
|
|
618
|
+
if (callbackReceived || cleaned) return;
|
|
619
|
+
setTimeout(() => {
|
|
620
|
+
if (callbackReceived || cleaned) return;
|
|
621
|
+
cleanup();
|
|
622
|
+
this.modal?.hideLoading();
|
|
623
|
+
}, 1500);
|
|
624
|
+
};
|
|
625
|
+
window.addEventListener("focus", focusHandler);
|
|
626
|
+
const maxTimer = setTimeout(() => {
|
|
627
|
+
if (callbackReceived || cleaned) return;
|
|
628
|
+
cleanup();
|
|
629
|
+
this.modal?.hideLoading();
|
|
630
|
+
}, 18e4);
|
|
631
|
+
if (!popup) {
|
|
632
|
+
cleanup();
|
|
633
|
+
this.modal?.hideLoading();
|
|
634
|
+
this.emit("error", new Error("Popup was blocked by the browser"));
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
622
637
|
const handler = async (e) => {
|
|
623
638
|
if (e.data?.type !== "authon-oauth-callback") return;
|
|
624
639
|
callbackReceived = true;
|
|
625
|
-
|
|
626
|
-
clearInterval(pollTimer);
|
|
640
|
+
cleanup();
|
|
627
641
|
try {
|
|
628
642
|
const tokens = await this.apiPost("/v1/auth/oauth/callback", {
|
|
629
643
|
code: e.data.code,
|
package/dist/index.mjs
CHANGED
|
@@ -579,24 +579,38 @@ var Authon = class {
|
|
|
579
579
|
`width=${width},height=${height},left=${left},top=${top},toolbar=no,menubar=no`
|
|
580
580
|
);
|
|
581
581
|
let callbackReceived = false;
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
582
|
+
let cleaned = false;
|
|
583
|
+
const cleanup = () => {
|
|
584
|
+
if (cleaned) return;
|
|
585
|
+
cleaned = true;
|
|
586
|
+
window.removeEventListener("message", handler);
|
|
587
|
+
window.removeEventListener("focus", focusHandler);
|
|
588
|
+
if (maxTimer) clearTimeout(maxTimer);
|
|
589
|
+
};
|
|
590
|
+
const focusHandler = () => {
|
|
591
|
+
if (callbackReceived || cleaned) return;
|
|
592
|
+
setTimeout(() => {
|
|
593
|
+
if (callbackReceived || cleaned) return;
|
|
594
|
+
cleanup();
|
|
595
|
+
this.modal?.hideLoading();
|
|
596
|
+
}, 1500);
|
|
597
|
+
};
|
|
598
|
+
window.addEventListener("focus", focusHandler);
|
|
599
|
+
const maxTimer = setTimeout(() => {
|
|
600
|
+
if (callbackReceived || cleaned) return;
|
|
601
|
+
cleanup();
|
|
602
|
+
this.modal?.hideLoading();
|
|
603
|
+
}, 18e4);
|
|
604
|
+
if (!popup) {
|
|
605
|
+
cleanup();
|
|
606
|
+
this.modal?.hideLoading();
|
|
607
|
+
this.emit("error", new Error("Popup was blocked by the browser"));
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
595
610
|
const handler = async (e) => {
|
|
596
611
|
if (e.data?.type !== "authon-oauth-callback") return;
|
|
597
612
|
callbackReceived = true;
|
|
598
|
-
|
|
599
|
-
clearInterval(pollTimer);
|
|
613
|
+
cleanup();
|
|
600
614
|
try {
|
|
601
615
|
const tokens = await this.apiPost("/v1/auth/oauth/callback", {
|
|
602
616
|
code: e.data.code,
|