@authon/js 0.7.0 → 0.7.2

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
@@ -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();
@@ -1726,6 +1742,7 @@ var ModalRenderer = class {
1726
1742
  if (form) {
1727
1743
  form.addEventListener("submit", (e) => {
1728
1744
  e.preventDefault();
1745
+ this.setSubmitLoading(true);
1729
1746
  const formData = new FormData(form);
1730
1747
  this.onEmailSubmit(
1731
1748
  formData.get("email"),
@@ -3073,6 +3090,10 @@ var Authon = class {
3073
3090
  "/v1/auth/signin",
3074
3091
  body
3075
3092
  );
3093
+ if (res.needsVerification) {
3094
+ this.emit("verificationRequired", res.email);
3095
+ return { needsVerification: true, email: res.email };
3096
+ }
3076
3097
  if (res.mfaRequired && res.mfaToken) {
3077
3098
  this.emit("mfaRequired", res.mfaToken);
3078
3099
  throw new AuthonMfaRequiredError(res.mfaToken);
@@ -3456,6 +3477,7 @@ var Authon = class {
3456
3477
  if (isSignUp) {
3457
3478
  this.signUpWithEmail(email, password, { turnstileToken }).then((result) => {
3458
3479
  if ("needsVerification" in result && result.needsVerification) {
3480
+ this.modal?.setSubmitLoading(false);
3459
3481
  this.modal?.showVerificationInput(email, async (code) => {
3460
3482
  try {
3461
3483
  await this.verifyEmail(email, code);
@@ -3472,13 +3494,32 @@ var Authon = class {
3472
3494
  }
3473
3495
  }).catch((err) => {
3474
3496
  this.modal?.resetTurnstile?.();
3497
+ this.modal?.setSubmitLoading(false);
3475
3498
  const msg = err instanceof Error ? err.message : String(err);
3476
3499
  this.modal?.showError(msg || "Authentication failed");
3477
3500
  this.emit("error", err instanceof Error ? err : new Error(msg));
3478
3501
  });
3479
3502
  } else {
3480
- this.signInWithEmail(email, password, turnstileToken).then(() => this.modal?.close()).catch((err) => {
3503
+ this.signInWithEmail(email, password, turnstileToken).then((result) => {
3504
+ if ("needsVerification" in result && result.needsVerification) {
3505
+ this.modal?.setSubmitLoading(false);
3506
+ this.modal?.showVerificationInput(email, async (code) => {
3507
+ try {
3508
+ await this.verifyEmail(email, code);
3509
+ this.modal?.close();
3510
+ } catch (err) {
3511
+ const msg = err instanceof Error ? err.message : String(err);
3512
+ this.modal?.showError(msg || "Verification failed");
3513
+ }
3514
+ }, async () => {
3515
+ await this.resendVerificationCode(email);
3516
+ });
3517
+ } else {
3518
+ this.modal?.close();
3519
+ }
3520
+ }).catch((err) => {
3481
3521
  this.modal?.resetTurnstile?.();
3522
+ this.modal?.setSubmitLoading(false);
3482
3523
  const msg = err instanceof Error ? err.message : String(err);
3483
3524
  this.modal?.showError(msg || "Authentication failed");
3484
3525
  this.emit("error", err instanceof Error ? err : new Error(msg));