@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 +42 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +42 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -49,7 +49,10 @@ declare class Authon {
|
|
|
49
49
|
/** Update theme at runtime without destroying form state */
|
|
50
50
|
setTheme(theme: 'light' | 'dark' | 'auto'): void;
|
|
51
51
|
signInWithOAuth(provider: OAuthProviderType, options?: OAuthSignInOptions): Promise<void>;
|
|
52
|
-
signInWithEmail(email: string, password: string, turnstileToken?: string): Promise<AuthonUser
|
|
52
|
+
signInWithEmail(email: string, password: string, turnstileToken?: string): Promise<AuthonUser | {
|
|
53
|
+
needsVerification: true;
|
|
54
|
+
email: string;
|
|
55
|
+
}>;
|
|
53
56
|
signUpWithEmail(email: string, password: string, meta?: {
|
|
54
57
|
displayName?: string;
|
|
55
58
|
turnstileToken?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -49,7 +49,10 @@ declare class Authon {
|
|
|
49
49
|
/** Update theme at runtime without destroying form state */
|
|
50
50
|
setTheme(theme: 'light' | 'dark' | 'auto'): void;
|
|
51
51
|
signInWithOAuth(provider: OAuthProviderType, options?: OAuthSignInOptions): Promise<void>;
|
|
52
|
-
signInWithEmail(email: string, password: string, turnstileToken?: string): Promise<AuthonUser
|
|
52
|
+
signInWithEmail(email: string, password: string, turnstileToken?: string): Promise<AuthonUser | {
|
|
53
|
+
needsVerification: true;
|
|
54
|
+
email: string;
|
|
55
|
+
}>;
|
|
53
56
|
signUpWithEmail(email: string, password: string, meta?: {
|
|
54
57
|
displayName?: string;
|
|
55
58
|
turnstileToken?: string;
|
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();
|
|
@@ -1694,6 +1710,7 @@ var ModalRenderer = class {
|
|
|
1694
1710
|
if (form) {
|
|
1695
1711
|
form.addEventListener("submit", (e) => {
|
|
1696
1712
|
e.preventDefault();
|
|
1713
|
+
this.setSubmitLoading(true);
|
|
1697
1714
|
const formData = new FormData(form);
|
|
1698
1715
|
this.onEmailSubmit(
|
|
1699
1716
|
formData.get("email"),
|
|
@@ -3041,6 +3058,10 @@ var Authon = class {
|
|
|
3041
3058
|
"/v1/auth/signin",
|
|
3042
3059
|
body
|
|
3043
3060
|
);
|
|
3061
|
+
if (res.needsVerification) {
|
|
3062
|
+
this.emit("verificationRequired", res.email);
|
|
3063
|
+
return { needsVerification: true, email: res.email };
|
|
3064
|
+
}
|
|
3044
3065
|
if (res.mfaRequired && res.mfaToken) {
|
|
3045
3066
|
this.emit("mfaRequired", res.mfaToken);
|
|
3046
3067
|
throw new AuthonMfaRequiredError(res.mfaToken);
|
|
@@ -3424,6 +3445,7 @@ var Authon = class {
|
|
|
3424
3445
|
if (isSignUp) {
|
|
3425
3446
|
this.signUpWithEmail(email, password, { turnstileToken }).then((result) => {
|
|
3426
3447
|
if ("needsVerification" in result && result.needsVerification) {
|
|
3448
|
+
this.modal?.setSubmitLoading(false);
|
|
3427
3449
|
this.modal?.showVerificationInput(email, async (code) => {
|
|
3428
3450
|
try {
|
|
3429
3451
|
await this.verifyEmail(email, code);
|
|
@@ -3440,13 +3462,32 @@ var Authon = class {
|
|
|
3440
3462
|
}
|
|
3441
3463
|
}).catch((err) => {
|
|
3442
3464
|
this.modal?.resetTurnstile?.();
|
|
3465
|
+
this.modal?.setSubmitLoading(false);
|
|
3443
3466
|
const msg = err instanceof Error ? err.message : String(err);
|
|
3444
3467
|
this.modal?.showError(msg || "Authentication failed");
|
|
3445
3468
|
this.emit("error", err instanceof Error ? err : new Error(msg));
|
|
3446
3469
|
});
|
|
3447
3470
|
} else {
|
|
3448
|
-
this.signInWithEmail(email, password, turnstileToken).then(() =>
|
|
3471
|
+
this.signInWithEmail(email, password, turnstileToken).then((result) => {
|
|
3472
|
+
if ("needsVerification" in result && result.needsVerification) {
|
|
3473
|
+
this.modal?.setSubmitLoading(false);
|
|
3474
|
+
this.modal?.showVerificationInput(email, async (code) => {
|
|
3475
|
+
try {
|
|
3476
|
+
await this.verifyEmail(email, code);
|
|
3477
|
+
this.modal?.close();
|
|
3478
|
+
} catch (err) {
|
|
3479
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
3480
|
+
this.modal?.showError(msg || "Verification failed");
|
|
3481
|
+
}
|
|
3482
|
+
}, async () => {
|
|
3483
|
+
await this.resendVerificationCode(email);
|
|
3484
|
+
});
|
|
3485
|
+
} else {
|
|
3486
|
+
this.modal?.close();
|
|
3487
|
+
}
|
|
3488
|
+
}).catch((err) => {
|
|
3449
3489
|
this.modal?.resetTurnstile?.();
|
|
3490
|
+
this.modal?.setSubmitLoading(false);
|
|
3450
3491
|
const msg = err instanceof Error ? err.message : String(err);
|
|
3451
3492
|
this.modal?.showError(msg || "Authentication failed");
|
|
3452
3493
|
this.emit("error", err instanceof Error ? err : new Error(msg));
|