@authon/js 0.7.1 → 0.7.3
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 +45 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +45 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -809,6 +809,7 @@ var ModalRenderer = class {
|
|
|
809
809
|
showError(message) {
|
|
810
810
|
if (!this.shadowRoot) return;
|
|
811
811
|
this.clearError();
|
|
812
|
+
this.setSubmitLoading(false);
|
|
812
813
|
const errorEl = this.shadowRoot.getElementById("email-form");
|
|
813
814
|
if (errorEl) {
|
|
814
815
|
const errDiv = document.createElement("div");
|
|
@@ -818,6 +819,21 @@ var ModalRenderer = class {
|
|
|
818
819
|
errorEl.appendChild(errDiv);
|
|
819
820
|
}
|
|
820
821
|
}
|
|
822
|
+
setSubmitLoading(loading) {
|
|
823
|
+
if (!this.shadowRoot) return;
|
|
824
|
+
const btn = this.shadowRoot.querySelector(".submit-btn");
|
|
825
|
+
if (!btn) return;
|
|
826
|
+
if (loading) {
|
|
827
|
+
btn.dataset.originalText = btn.textContent || "";
|
|
828
|
+
btn.innerHTML = '<span style="display:inline-flex;align-items:center;gap:6px"><svg width="14" height="14" viewBox="0 0 14 14" style="animation:spin 0.8s linear infinite"><circle cx="7" cy="7" r="5" fill="none" stroke="currentColor" stroke-width="2" opacity="0.3"/><path d="M7 2a5 5 0 0 1 5 5" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg></span>';
|
|
829
|
+
btn.disabled = true;
|
|
830
|
+
btn.style.opacity = "0.7";
|
|
831
|
+
} else {
|
|
832
|
+
btn.innerHTML = btn.dataset.originalText || "Continue";
|
|
833
|
+
btn.disabled = false;
|
|
834
|
+
btn.style.opacity = "1";
|
|
835
|
+
}
|
|
836
|
+
}
|
|
821
837
|
showBanner(message, type = "error") {
|
|
822
838
|
if (!this.shadowRoot) return;
|
|
823
839
|
this.clearBanner();
|
|
@@ -850,6 +866,7 @@ var ModalRenderer = class {
|
|
|
850
866
|
<p style="font-size:13px;color:var(--authon-muted);margin-bottom:20px">${email}</p>
|
|
851
867
|
</div>
|
|
852
868
|
<div class="email-form" id="verify-form">
|
|
869
|
+
<div id="verify-error" style="display:none;padding:8px 12px;background:rgba(239,68,68,0.1);border:1px solid rgba(239,68,68,0.3);border-radius:8px;font-size:13px;color:#ef4444;text-align:center;margin-bottom:4px"></div>
|
|
853
870
|
<input type="text" id="verify-code" class="input" placeholder="000000" maxlength="6" inputmode="numeric" autocomplete="one-time-code" style="text-align:center;font-size:20px;letter-spacing:0.2em;font-family:ui-monospace,monospace" />
|
|
854
871
|
<button type="button" id="verify-submit" class="submit-btn">${this.t.signIn}</button>
|
|
855
872
|
</div>
|
|
@@ -864,12 +881,30 @@ var ModalRenderer = class {
|
|
|
864
881
|
codeInput?.addEventListener("input", () => {
|
|
865
882
|
codeInput.value = codeInput.value.replace(/\D/g, "").slice(0, 6);
|
|
866
883
|
});
|
|
884
|
+
const verifyError = this.shadowRoot.getElementById("verify-error");
|
|
867
885
|
submitBtn?.addEventListener("click", async () => {
|
|
868
886
|
const code = codeInput?.value?.trim();
|
|
869
887
|
if (!code || code.length < 6) return;
|
|
888
|
+
if (verifyError) {
|
|
889
|
+
verifyError.style.display = "none";
|
|
890
|
+
}
|
|
870
891
|
submitBtn.textContent = "...";
|
|
871
892
|
submitBtn.disabled = true;
|
|
872
|
-
|
|
893
|
+
try {
|
|
894
|
+
await onVerify(code);
|
|
895
|
+
} catch (err) {
|
|
896
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
897
|
+
if (verifyError) {
|
|
898
|
+
verifyError.textContent = msg || "Verification failed";
|
|
899
|
+
verifyError.style.display = "block";
|
|
900
|
+
}
|
|
901
|
+
submitBtn.textContent = this.t.signIn;
|
|
902
|
+
submitBtn.disabled = false;
|
|
903
|
+
if (codeInput) {
|
|
904
|
+
codeInput.value = "";
|
|
905
|
+
codeInput.focus();
|
|
906
|
+
}
|
|
907
|
+
}
|
|
873
908
|
});
|
|
874
909
|
codeInput?.addEventListener("keydown", (e) => {
|
|
875
910
|
if (e.key === "Enter") submitBtn?.click();
|
|
@@ -1726,6 +1761,7 @@ var ModalRenderer = class {
|
|
|
1726
1761
|
if (form) {
|
|
1727
1762
|
form.addEventListener("submit", (e) => {
|
|
1728
1763
|
e.preventDefault();
|
|
1764
|
+
this.setSubmitLoading(true);
|
|
1729
1765
|
const formData = new FormData(form);
|
|
1730
1766
|
this.onEmailSubmit(
|
|
1731
1767
|
formData.get("email"),
|
|
@@ -3460,14 +3496,10 @@ var Authon = class {
|
|
|
3460
3496
|
if (isSignUp) {
|
|
3461
3497
|
this.signUpWithEmail(email, password, { turnstileToken }).then((result) => {
|
|
3462
3498
|
if ("needsVerification" in result && result.needsVerification) {
|
|
3499
|
+
this.modal?.setSubmitLoading(false);
|
|
3463
3500
|
this.modal?.showVerificationInput(email, async (code) => {
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
this.modal?.close();
|
|
3467
|
-
} catch (err) {
|
|
3468
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
3469
|
-
this.modal?.showError(msg || "Verification failed");
|
|
3470
|
-
}
|
|
3501
|
+
await this.verifyEmail(email, code);
|
|
3502
|
+
this.modal?.close();
|
|
3471
3503
|
}, async () => {
|
|
3472
3504
|
await this.resendVerificationCode(email);
|
|
3473
3505
|
});
|
|
@@ -3476,6 +3508,7 @@ var Authon = class {
|
|
|
3476
3508
|
}
|
|
3477
3509
|
}).catch((err) => {
|
|
3478
3510
|
this.modal?.resetTurnstile?.();
|
|
3511
|
+
this.modal?.setSubmitLoading(false);
|
|
3479
3512
|
const msg = err instanceof Error ? err.message : String(err);
|
|
3480
3513
|
this.modal?.showError(msg || "Authentication failed");
|
|
3481
3514
|
this.emit("error", err instanceof Error ? err : new Error(msg));
|
|
@@ -3483,14 +3516,10 @@ var Authon = class {
|
|
|
3483
3516
|
} else {
|
|
3484
3517
|
this.signInWithEmail(email, password, turnstileToken).then((result) => {
|
|
3485
3518
|
if ("needsVerification" in result && result.needsVerification) {
|
|
3519
|
+
this.modal?.setSubmitLoading(false);
|
|
3486
3520
|
this.modal?.showVerificationInput(email, async (code) => {
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
this.modal?.close();
|
|
3490
|
-
} catch (err) {
|
|
3491
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
3492
|
-
this.modal?.showError(msg || "Verification failed");
|
|
3493
|
-
}
|
|
3521
|
+
await this.verifyEmail(email, code);
|
|
3522
|
+
this.modal?.close();
|
|
3494
3523
|
}, async () => {
|
|
3495
3524
|
await this.resendVerificationCode(email);
|
|
3496
3525
|
});
|
|
@@ -3499,6 +3528,7 @@ var Authon = class {
|
|
|
3499
3528
|
}
|
|
3500
3529
|
}).catch((err) => {
|
|
3501
3530
|
this.modal?.resetTurnstile?.();
|
|
3531
|
+
this.modal?.setSubmitLoading(false);
|
|
3502
3532
|
const msg = err instanceof Error ? err.message : String(err);
|
|
3503
3533
|
this.modal?.showError(msg || "Authentication failed");
|
|
3504
3534
|
this.emit("error", err instanceof Error ? err : new Error(msg));
|