@authon/js 0.6.0 → 0.7.1
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 +115 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +115 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -49,11 +49,19 @@ 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;
|
|
56
|
-
}): Promise<AuthonUser
|
|
59
|
+
}): Promise<AuthonUser | {
|
|
60
|
+
needsVerification: true;
|
|
61
|
+
email: string;
|
|
62
|
+
}>;
|
|
63
|
+
verifyEmail(email: string, code: string): Promise<AuthonUser>;
|
|
64
|
+
resendVerificationCode(email: string): Promise<void>;
|
|
57
65
|
signOut(): Promise<void>;
|
|
58
66
|
getUser(): AuthonUser | null;
|
|
59
67
|
getToken(): string | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -49,11 +49,19 @@ 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;
|
|
56
|
-
}): Promise<AuthonUser
|
|
59
|
+
}): Promise<AuthonUser | {
|
|
60
|
+
needsVerification: true;
|
|
61
|
+
email: string;
|
|
62
|
+
}>;
|
|
63
|
+
verifyEmail(email: string, code: string): Promise<AuthonUser>;
|
|
64
|
+
resendVerificationCode(email: string): Promise<void>;
|
|
57
65
|
signOut(): Promise<void>;
|
|
58
66
|
getUser(): AuthonUser | null;
|
|
59
67
|
getToken(): string | null;
|
package/dist/index.js
CHANGED
|
@@ -805,6 +805,53 @@ var ModalRenderer = class {
|
|
|
805
805
|
if (!this.shadowRoot) return;
|
|
806
806
|
this.shadowRoot.getElementById("authon-error-msg")?.remove();
|
|
807
807
|
}
|
|
808
|
+
showVerificationInput(email, onVerify, onResend) {
|
|
809
|
+
if (!this.shadowRoot) return;
|
|
810
|
+
const inner = this.shadowRoot.querySelector(".modal-inner");
|
|
811
|
+
if (!inner) return;
|
|
812
|
+
inner.innerHTML = `
|
|
813
|
+
<div style="text-align:center;padding:8px 0">
|
|
814
|
+
<div style="width:48px;height:48px;border-radius:12px;background:color-mix(in srgb, var(--authon-primary-start) 15%, transparent);display:flex;align-items:center;justify-content:center;margin:0 auto 16px">
|
|
815
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="var(--authon-primary-start)" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"/><polyline points="22,6 12,13 2,6"/></svg>
|
|
816
|
+
</div>
|
|
817
|
+
<h2 class="title" style="font-size:20px;margin-bottom:4px">${this.t.welcomeBack.includes("Welcome") ? "Check your email" : this.t.welcomeBack}</h2>
|
|
818
|
+
<p style="font-size:13px;color:var(--authon-muted);margin-bottom:20px">${email}</p>
|
|
819
|
+
</div>
|
|
820
|
+
<div class="email-form" id="verify-form">
|
|
821
|
+
<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
|
+
<button type="button" id="verify-submit" class="submit-btn">${this.t.signIn}</button>
|
|
823
|
+
</div>
|
|
824
|
+
<p style="text-align:center;margin-top:12px;font-size:12px;color:var(--authon-dim)">
|
|
825
|
+
<a href="#" id="resend-link" style="color:var(--authon-primary-start);text-decoration:none;font-weight:500">${this.t.backToSignIn.includes("Back") ? "Resend code" : this.t.backToSignIn}</a>
|
|
826
|
+
</p>
|
|
827
|
+
`;
|
|
828
|
+
const codeInput = this.shadowRoot.getElementById("verify-code");
|
|
829
|
+
const submitBtn = this.shadowRoot.getElementById("verify-submit");
|
|
830
|
+
const resendLink = this.shadowRoot.getElementById("resend-link");
|
|
831
|
+
codeInput?.focus();
|
|
832
|
+
codeInput?.addEventListener("input", () => {
|
|
833
|
+
codeInput.value = codeInput.value.replace(/\D/g, "").slice(0, 6);
|
|
834
|
+
});
|
|
835
|
+
submitBtn?.addEventListener("click", async () => {
|
|
836
|
+
const code = codeInput?.value?.trim();
|
|
837
|
+
if (!code || code.length < 6) return;
|
|
838
|
+
submitBtn.textContent = "...";
|
|
839
|
+
submitBtn.disabled = true;
|
|
840
|
+
await onVerify(code);
|
|
841
|
+
});
|
|
842
|
+
codeInput?.addEventListener("keydown", (e) => {
|
|
843
|
+
if (e.key === "Enter") submitBtn?.click();
|
|
844
|
+
});
|
|
845
|
+
resendLink?.addEventListener("click", async (e) => {
|
|
846
|
+
e.preventDefault();
|
|
847
|
+
resendLink.textContent = "...";
|
|
848
|
+
await onResend();
|
|
849
|
+
resendLink.textContent = "Sent!";
|
|
850
|
+
setTimeout(() => {
|
|
851
|
+
resendLink.textContent = "Resend code";
|
|
852
|
+
}, 2e3);
|
|
853
|
+
});
|
|
854
|
+
}
|
|
808
855
|
showLoading() {
|
|
809
856
|
if (!this.shadowRoot) return;
|
|
810
857
|
this.hideLoading();
|
|
@@ -2994,6 +3041,10 @@ var Authon = class {
|
|
|
2994
3041
|
"/v1/auth/signin",
|
|
2995
3042
|
body
|
|
2996
3043
|
);
|
|
3044
|
+
if (res.needsVerification) {
|
|
3045
|
+
this.emit("verificationRequired", res.email);
|
|
3046
|
+
return { needsVerification: true, email: res.email };
|
|
3047
|
+
}
|
|
2997
3048
|
if (res.mfaRequired && res.mfaToken) {
|
|
2998
3049
|
this.emit("mfaRequired", res.mfaToken);
|
|
2999
3050
|
throw new AuthonMfaRequiredError(res.mfaToken);
|
|
@@ -3003,14 +3054,27 @@ var Authon = class {
|
|
|
3003
3054
|
return res.user;
|
|
3004
3055
|
}
|
|
3005
3056
|
async signUpWithEmail(email, password, meta) {
|
|
3006
|
-
const
|
|
3057
|
+
const res = await this.apiPost("/v1/auth/signup", {
|
|
3007
3058
|
email,
|
|
3008
3059
|
password,
|
|
3009
3060
|
...meta
|
|
3010
3061
|
});
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3062
|
+
if (res.needsVerification) {
|
|
3063
|
+
this.emit("verificationRequired", res.email);
|
|
3064
|
+
return { needsVerification: true, email: res.email };
|
|
3065
|
+
}
|
|
3066
|
+
this.session.setSession(res);
|
|
3067
|
+
this.emit("signedIn", res.user);
|
|
3068
|
+
return res.user;
|
|
3069
|
+
}
|
|
3070
|
+
async verifyEmail(email, code) {
|
|
3071
|
+
const res = await this.apiPost("/v1/auth/verify-email", { email, code });
|
|
3072
|
+
this.session.setSession(res);
|
|
3073
|
+
this.emit("signedIn", res.user);
|
|
3074
|
+
return res.user;
|
|
3075
|
+
}
|
|
3076
|
+
async resendVerificationCode(email) {
|
|
3077
|
+
await this.apiPost("/v1/auth/resend-code", { email });
|
|
3014
3078
|
}
|
|
3015
3079
|
async signOut() {
|
|
3016
3080
|
await this.session.signOut();
|
|
@@ -3361,13 +3425,53 @@ var Authon = class {
|
|
|
3361
3425
|
onEmailSubmit: (email, password, isSignUp) => {
|
|
3362
3426
|
this.modal?.clearError();
|
|
3363
3427
|
const turnstileToken = this.modal?.getTurnstileToken?.() || void 0;
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3428
|
+
if (isSignUp) {
|
|
3429
|
+
this.signUpWithEmail(email, password, { turnstileToken }).then((result) => {
|
|
3430
|
+
if ("needsVerification" in result && result.needsVerification) {
|
|
3431
|
+
this.modal?.showVerificationInput(email, async (code) => {
|
|
3432
|
+
try {
|
|
3433
|
+
await this.verifyEmail(email, code);
|
|
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
|
+
}
|
|
3439
|
+
}, async () => {
|
|
3440
|
+
await this.resendVerificationCode(email);
|
|
3441
|
+
});
|
|
3442
|
+
} else {
|
|
3443
|
+
this.modal?.close();
|
|
3444
|
+
}
|
|
3445
|
+
}).catch((err) => {
|
|
3446
|
+
this.modal?.resetTurnstile?.();
|
|
3447
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
3448
|
+
this.modal?.showError(msg || "Authentication failed");
|
|
3449
|
+
this.emit("error", err instanceof Error ? err : new Error(msg));
|
|
3450
|
+
});
|
|
3451
|
+
} else {
|
|
3452
|
+
this.signInWithEmail(email, password, turnstileToken).then((result) => {
|
|
3453
|
+
if ("needsVerification" in result && result.needsVerification) {
|
|
3454
|
+
this.modal?.showVerificationInput(email, async (code) => {
|
|
3455
|
+
try {
|
|
3456
|
+
await this.verifyEmail(email, code);
|
|
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
|
+
}
|
|
3462
|
+
}, async () => {
|
|
3463
|
+
await this.resendVerificationCode(email);
|
|
3464
|
+
});
|
|
3465
|
+
} else {
|
|
3466
|
+
this.modal?.close();
|
|
3467
|
+
}
|
|
3468
|
+
}).catch((err) => {
|
|
3469
|
+
this.modal?.resetTurnstile?.();
|
|
3470
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
3471
|
+
this.modal?.showError(msg || "Authentication failed");
|
|
3472
|
+
this.emit("error", err instanceof Error ? err : new Error(msg));
|
|
3473
|
+
});
|
|
3474
|
+
}
|
|
3371
3475
|
},
|
|
3372
3476
|
onClose: () => this.modal?.close(),
|
|
3373
3477
|
onWeb3WalletSelect: async (walletId) => {
|