@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.js
CHANGED
|
@@ -777,6 +777,7 @@ var ModalRenderer = class {
|
|
|
777
777
|
showError(message) {
|
|
778
778
|
if (!this.shadowRoot) return;
|
|
779
779
|
this.clearError();
|
|
780
|
+
this.setSubmitLoading(false);
|
|
780
781
|
const errorEl = this.shadowRoot.getElementById("email-form");
|
|
781
782
|
if (errorEl) {
|
|
782
783
|
const errDiv = document.createElement("div");
|
|
@@ -786,6 +787,21 @@ var ModalRenderer = class {
|
|
|
786
787
|
errorEl.appendChild(errDiv);
|
|
787
788
|
}
|
|
788
789
|
}
|
|
790
|
+
setSubmitLoading(loading) {
|
|
791
|
+
if (!this.shadowRoot) return;
|
|
792
|
+
const btn = this.shadowRoot.querySelector(".submit-btn");
|
|
793
|
+
if (!btn) return;
|
|
794
|
+
if (loading) {
|
|
795
|
+
btn.dataset.originalText = btn.textContent || "";
|
|
796
|
+
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>';
|
|
797
|
+
btn.disabled = true;
|
|
798
|
+
btn.style.opacity = "0.7";
|
|
799
|
+
} else {
|
|
800
|
+
btn.innerHTML = btn.dataset.originalText || "Continue";
|
|
801
|
+
btn.disabled = false;
|
|
802
|
+
btn.style.opacity = "1";
|
|
803
|
+
}
|
|
804
|
+
}
|
|
789
805
|
showBanner(message, type = "error") {
|
|
790
806
|
if (!this.shadowRoot) return;
|
|
791
807
|
this.clearBanner();
|
|
@@ -818,6 +834,7 @@ var ModalRenderer = class {
|
|
|
818
834
|
<p style="font-size:13px;color:var(--authon-muted);margin-bottom:20px">${email}</p>
|
|
819
835
|
</div>
|
|
820
836
|
<div class="email-form" id="verify-form">
|
|
837
|
+
<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>
|
|
821
838
|
<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" />
|
|
822
839
|
<button type="button" id="verify-submit" class="submit-btn">${this.t.signIn}</button>
|
|
823
840
|
</div>
|
|
@@ -832,12 +849,30 @@ var ModalRenderer = class {
|
|
|
832
849
|
codeInput?.addEventListener("input", () => {
|
|
833
850
|
codeInput.value = codeInput.value.replace(/\D/g, "").slice(0, 6);
|
|
834
851
|
});
|
|
852
|
+
const verifyError = this.shadowRoot.getElementById("verify-error");
|
|
835
853
|
submitBtn?.addEventListener("click", async () => {
|
|
836
854
|
const code = codeInput?.value?.trim();
|
|
837
855
|
if (!code || code.length < 6) return;
|
|
856
|
+
if (verifyError) {
|
|
857
|
+
verifyError.style.display = "none";
|
|
858
|
+
}
|
|
838
859
|
submitBtn.textContent = "...";
|
|
839
860
|
submitBtn.disabled = true;
|
|
840
|
-
|
|
861
|
+
try {
|
|
862
|
+
await onVerify(code);
|
|
863
|
+
} catch (err) {
|
|
864
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
865
|
+
if (verifyError) {
|
|
866
|
+
verifyError.textContent = msg || "Verification failed";
|
|
867
|
+
verifyError.style.display = "block";
|
|
868
|
+
}
|
|
869
|
+
submitBtn.textContent = this.t.signIn;
|
|
870
|
+
submitBtn.disabled = false;
|
|
871
|
+
if (codeInput) {
|
|
872
|
+
codeInput.value = "";
|
|
873
|
+
codeInput.focus();
|
|
874
|
+
}
|
|
875
|
+
}
|
|
841
876
|
});
|
|
842
877
|
codeInput?.addEventListener("keydown", (e) => {
|
|
843
878
|
if (e.key === "Enter") submitBtn?.click();
|
|
@@ -1694,6 +1729,7 @@ var ModalRenderer = class {
|
|
|
1694
1729
|
if (form) {
|
|
1695
1730
|
form.addEventListener("submit", (e) => {
|
|
1696
1731
|
e.preventDefault();
|
|
1732
|
+
this.setSubmitLoading(true);
|
|
1697
1733
|
const formData = new FormData(form);
|
|
1698
1734
|
this.onEmailSubmit(
|
|
1699
1735
|
formData.get("email"),
|
|
@@ -3428,14 +3464,10 @@ var Authon = class {
|
|
|
3428
3464
|
if (isSignUp) {
|
|
3429
3465
|
this.signUpWithEmail(email, password, { turnstileToken }).then((result) => {
|
|
3430
3466
|
if ("needsVerification" in result && result.needsVerification) {
|
|
3467
|
+
this.modal?.setSubmitLoading(false);
|
|
3431
3468
|
this.modal?.showVerificationInput(email, async (code) => {
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
this.modal?.close();
|
|
3435
|
-
} catch (err) {
|
|
3436
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
3437
|
-
this.modal?.showError(msg || "Verification failed");
|
|
3438
|
-
}
|
|
3469
|
+
await this.verifyEmail(email, code);
|
|
3470
|
+
this.modal?.close();
|
|
3439
3471
|
}, async () => {
|
|
3440
3472
|
await this.resendVerificationCode(email);
|
|
3441
3473
|
});
|
|
@@ -3444,6 +3476,7 @@ var Authon = class {
|
|
|
3444
3476
|
}
|
|
3445
3477
|
}).catch((err) => {
|
|
3446
3478
|
this.modal?.resetTurnstile?.();
|
|
3479
|
+
this.modal?.setSubmitLoading(false);
|
|
3447
3480
|
const msg = err instanceof Error ? err.message : String(err);
|
|
3448
3481
|
this.modal?.showError(msg || "Authentication failed");
|
|
3449
3482
|
this.emit("error", err instanceof Error ? err : new Error(msg));
|
|
@@ -3451,14 +3484,10 @@ var Authon = class {
|
|
|
3451
3484
|
} else {
|
|
3452
3485
|
this.signInWithEmail(email, password, turnstileToken).then((result) => {
|
|
3453
3486
|
if ("needsVerification" in result && result.needsVerification) {
|
|
3487
|
+
this.modal?.setSubmitLoading(false);
|
|
3454
3488
|
this.modal?.showVerificationInput(email, async (code) => {
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
this.modal?.close();
|
|
3458
|
-
} catch (err) {
|
|
3459
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
3460
|
-
this.modal?.showError(msg || "Verification failed");
|
|
3461
|
-
}
|
|
3489
|
+
await this.verifyEmail(email, code);
|
|
3490
|
+
this.modal?.close();
|
|
3462
3491
|
}, async () => {
|
|
3463
3492
|
await this.resendVerificationCode(email);
|
|
3464
3493
|
});
|
|
@@ -3467,6 +3496,7 @@ var Authon = class {
|
|
|
3467
3496
|
}
|
|
3468
3497
|
}).catch((err) => {
|
|
3469
3498
|
this.modal?.resetTurnstile?.();
|
|
3499
|
+
this.modal?.setSubmitLoading(false);
|
|
3470
3500
|
const msg = err instanceof Error ? err.message : String(err);
|
|
3471
3501
|
this.modal?.showError(msg || "Authentication failed");
|
|
3472
3502
|
this.emit("error", err instanceof Error ? err : new Error(msg));
|