mirror of
https://github.com/bitbaum/accountkit.git
synced 2026-12-05 11:47:06 +01:00
* feat(auth): Lightning login (LNURL-auth, LUD-04), opt-in per deployment A free, Bitcoin-native way in: the person's own Lightning wallet signs a one-time challenge shown as a QR code (or opened through a lightning: link on the same device). No key, no third party, nothing paid. The signed key is a sign-in method (providerId "lightning"), never an email. - /lightning/start mints a challenge (five minutes, used once) and binds it to the asking browser with a signed cookie; /lightning/callback is the wallet's LUD-04 call and checks the DER secp256k1 signature of k1; /sign-in/lightning (polled) signs in or creates the person; /lightning/link adds a wallet to the signed-in person, never one that already signs in to someone else. - A second factor applies; minting and the wallet's call spend the credential bucket. - SignInForm and SignUpForm offer "Sign in with a Lightning wallet", AccountPanel "Add Lightning wallet"; words in all six languages. - Off until ACCOUNTKIT_LIGHTNING=1. Tests: LUD-01's own LNURL both ways, a signature made by OpenSSL, and the whole flow on a real database (PGlite) with a wallet that signs as LUD-04 says: sign-in and sign-in again, a forged signature, an onlooker without the browser's cookie, a second factor, linking and a taken wallet, and nothing mounted without the opt-in. Browser: QR, wallet link, 44px, no sideways scroll at 320 and 390px. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9 * feat(screens): a product's own GitHub app on the shared screens Loki keeps its GitHub sign-in (its own app, githubSignIn: true). The shared screens drew only the shared sign-in and OrangeCat, so Loki could not move onto SignInForm without losing it. signInMethods takes githubSignIn and reports methods.github; SignInForm, SignUpForm and AccountPanel draw it beside OrangeCat. The variables alone still offer nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9 --------- Co-authored-by: Claude <noreply@anthropic.com>
475 lines
28 KiB
JavaScript
475 lines
28 KiB
JavaScript
"use client";
|
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
import { useCallback, useEffect, useState, } from "react";
|
|
import { PasswordRecoveryForm } from "./recovery.js";
|
|
import { unbroken } from "./unbroken.js";
|
|
import { DEFAULT_AUTH_LABELS, authErrorText, fill, signinButtonLabel, } from "./labels.js";
|
|
import { PasswordField } from "./password-field.js";
|
|
import { LightningLogin, lightningWords, } from "./lightning-login.js";
|
|
/** Class names styled by @bitbaum/accountkit/styles.css on --acct-* variables. */
|
|
export const DEFAULT_AUTH_CLASSES = {
|
|
button: "acct-auth-button",
|
|
buttonQuiet: "acct-auth-button-quiet",
|
|
input: "acct-auth-input",
|
|
label: "acct-auth-label",
|
|
hint: "acct-auth-hint",
|
|
notice: "acct-auth-notice",
|
|
error: "acct-auth-error",
|
|
section: "acct-auth-section",
|
|
sectionTitle: "acct-auth-section-title",
|
|
divider: "acct-auth-divider",
|
|
link: "acct-auth-link",
|
|
stack: "acct-auth-stack",
|
|
field: "acct-auth-field",
|
|
check: "acct-auth-check",
|
|
inputWrap: "acct-auth-input-wrap",
|
|
reveal: "acct-auth-reveal",
|
|
};
|
|
const merge = (c) => ({
|
|
...DEFAULT_AUTH_CLASSES,
|
|
...c,
|
|
});
|
|
function ErrorLine({ message, className, }) {
|
|
if (!message)
|
|
return null;
|
|
return (_jsx("p", { role: "alert", className: className, children: message }));
|
|
}
|
|
const hasOidc = (methods) => methods.signin || methods.orangecat || Boolean(methods.github);
|
|
function Divider({ label, className }) {
|
|
return (_jsx("div", { className: className, role: "separator", children: _jsx("span", { children: label }) }));
|
|
}
|
|
/** "Continue with …" for each OIDC method this deployment has switched on. */
|
|
export function OidcButtons({ client, methods, labels = DEFAULT_AUTH_LABELS, classes, callbackURL, errorCallbackURL, onError, }) {
|
|
const c = merge(classes);
|
|
const [busy, setBusy] = useState(null);
|
|
const providers = [
|
|
methods.signin
|
|
? {
|
|
id: "bitbaum-signin",
|
|
label: signinButtonLabel(labels, methods.signinProviders),
|
|
}
|
|
: null,
|
|
methods.orangecat ? { id: "orangecat", label: labels.withOrangecat } : null,
|
|
methods.github
|
|
? {
|
|
id: "github",
|
|
label: labels.withGithub ?? DEFAULT_AUTH_LABELS.withGithub,
|
|
}
|
|
: null,
|
|
].filter((p) => p !== null);
|
|
if (providers.length === 0)
|
|
return null;
|
|
return (_jsx("div", { className: c.stack, children: providers.map((provider) => (_jsx("button", { type: "button", className: c.buttonQuiet, disabled: busy !== null, onClick: async () => {
|
|
setBusy(provider.id);
|
|
const { error } = await client.signIn.social({
|
|
provider: provider.id,
|
|
callbackURL,
|
|
errorCallbackURL,
|
|
});
|
|
if (error) {
|
|
onError(error);
|
|
setBusy(null);
|
|
}
|
|
}, children: unbroken(provider.label) }, provider.id))) }));
|
|
}
|
|
/**
|
|
* Every way in, on one screen: password, passkey, a link by email, and the
|
|
* OIDC buttons this deployment has switched on. A second factor, when the
|
|
* account has one, is asked for on the same card.
|
|
*/
|
|
export function SignInForm({ client, methods, labels = DEFAULT_AUTH_LABELS, classes, next, signInPath, signUpLink, initialError = false, }) {
|
|
const c = merge(classes);
|
|
const [step, setStep] = useState("start");
|
|
const [email, setEmail] = useState("");
|
|
const [password, setPassword] = useState("");
|
|
const [code, setCode] = useState("");
|
|
const [useBackup, setUseBackup] = useState(false);
|
|
const [trustDevice, setTrustDevice] = useState(false);
|
|
const [busy, setBusy] = useState(false);
|
|
const [error, setError] = useState(initialError ? labels.errors.generic : null);
|
|
const [unverified, setUnverified] = useState(false);
|
|
// The link's email also carries a code when the server says so (./sign-in-code).
|
|
const [codeSent, setCodeSent] = useState(false);
|
|
const [signInCode, setSignInCode] = useState("");
|
|
const [recovery, setRecovery] = useState(null);
|
|
useEffect(() => {
|
|
const query = new URLSearchParams(window.location.search);
|
|
const token = query.get("token");
|
|
const linkError = query.get("method") === "magic-link" && query.has("error");
|
|
if (linkError)
|
|
setError(labels.errors.SESSION_EXPIRED);
|
|
if (!token && query.get("twoFactor") === "1")
|
|
setStep("twoFactor");
|
|
if (token || (!linkError && query.get("error") === "INVALID_TOKEN")) {
|
|
setRecovery({ token: token || undefined, invalid: !token });
|
|
// Keep bearer reset credentials out of the address bar, referrers and history.
|
|
const url = new URL(window.location.href);
|
|
url.searchParams.delete("token");
|
|
url.searchParams.delete("error");
|
|
window.history.replaceState(null, "", url.pathname + url.search + url.hash);
|
|
}
|
|
}, [labels]);
|
|
const fail = (e) => {
|
|
setError(authErrorText(labels, e));
|
|
setUnverified(e?.code === "EMAIL_NOT_VERIFIED");
|
|
setBusy(false);
|
|
};
|
|
const done = () => window.location.assign(next);
|
|
async function withPassword(event) {
|
|
event.preventDefault();
|
|
setBusy(true);
|
|
setError(null);
|
|
const { data, error: e } = await client.signIn.email({
|
|
email,
|
|
password,
|
|
callbackURL: next,
|
|
});
|
|
if (e)
|
|
return fail(e);
|
|
if (data &&
|
|
typeof data === "object" &&
|
|
"twoFactorRedirect" in data &&
|
|
data.twoFactorRedirect) {
|
|
setStep("twoFactor");
|
|
setBusy(false);
|
|
return;
|
|
}
|
|
done();
|
|
}
|
|
async function withSecondFactor(event) {
|
|
event.preventDefault();
|
|
setBusy(true);
|
|
setError(null);
|
|
const input = { code: code.trim(), trustDevice };
|
|
const { error: e } = useBackup
|
|
? await client.twoFactor.verifyBackupCode(input)
|
|
: await client.twoFactor.verifyTotp(input);
|
|
if (e)
|
|
return fail(e);
|
|
done();
|
|
}
|
|
async function withLink() {
|
|
if (!email)
|
|
return setError(labels.errors.emailFirst);
|
|
setBusy(true);
|
|
setError(null);
|
|
const { data, error: e } = await client.signIn.magicLink({
|
|
email,
|
|
callbackURL: next,
|
|
errorCallbackURL: `${signInPath}?method=magic-link&next=${encodeURIComponent(next)}`,
|
|
});
|
|
if (e)
|
|
return fail(e);
|
|
setCodeSent(Boolean(client.signIn.emailOtp &&
|
|
data &&
|
|
typeof data === "object" &&
|
|
"code" in data &&
|
|
data.code === true));
|
|
setSignInCode("");
|
|
setStep("linkSent");
|
|
setBusy(false);
|
|
}
|
|
async function withCode(event) {
|
|
event.preventDefault();
|
|
if (!client.signIn.emailOtp)
|
|
return;
|
|
setBusy(true);
|
|
setError(null);
|
|
const { data, error: e } = await client.signIn.emailOtp({
|
|
email,
|
|
otp: signInCode.replace(/\s+/g, ""),
|
|
});
|
|
if (e)
|
|
return fail(e);
|
|
if (data &&
|
|
typeof data === "object" &&
|
|
"twoFactorRedirect" in data &&
|
|
data.twoFactorRedirect) {
|
|
setStep("twoFactor");
|
|
setBusy(false);
|
|
return;
|
|
}
|
|
done();
|
|
}
|
|
async function withPasskey() {
|
|
setBusy(true);
|
|
setError(null);
|
|
const result = await client.signIn.passkey();
|
|
if (result?.error)
|
|
return fail(result.error);
|
|
if (result &&
|
|
"data" in result &&
|
|
result.data &&
|
|
typeof result.data === "object" &&
|
|
"twoFactorRedirect" in result.data &&
|
|
result.data.twoFactorRedirect) {
|
|
setStep("twoFactor");
|
|
setBusy(false);
|
|
return;
|
|
}
|
|
done();
|
|
}
|
|
async function resendVerification() {
|
|
setBusy(true);
|
|
const { error: e } = await client.sendVerificationEmail({
|
|
email,
|
|
callbackURL: next,
|
|
});
|
|
if (e)
|
|
return fail(e);
|
|
setUnverified(false);
|
|
setStep("linkSent");
|
|
setBusy(false);
|
|
}
|
|
if (recovery) {
|
|
return (_jsx(PasswordRecoveryForm, { client: client, methods: methods, labels: labels, classes: classes, signInPath: signInPath, next: next, initialEmail: email, token: recovery.token, invalidToken: recovery.invalid, onBack: () => {
|
|
setRecovery(null);
|
|
setError(null);
|
|
setPassword("");
|
|
setStep("start");
|
|
} }));
|
|
}
|
|
if (step === "lightning" && client.lightning) {
|
|
return (_jsx(LightningLogin, { client: client.lightning, labels: labels, classes: c, purpose: "sign-in", onDone: done, onTwoFactor: () => setStep("twoFactor"), onBack: () => setStep("start") }));
|
|
}
|
|
if (step === "linkSent") {
|
|
return (_jsxs("div", { className: c.stack, children: [_jsx("p", { className: c.notice, role: "status", children: fill(labels.checkInbox, { email }) }), codeSent && (_jsxs("form", { onSubmit: withCode, className: c.stack, children: [_jsxs("div", { className: c.field, children: [_jsx("label", { htmlFor: "acct-sign-in-code", className: c.label, children: labels.codePrompt ?? DEFAULT_AUTH_LABELS.codePrompt }), _jsx("input", { id: "acct-sign-in-code", className: c.input, inputMode: "numeric", autoComplete: "one-time-code", pattern: "[0-9 ]*", maxLength: 7, value: signInCode, onChange: (e) => setSignInCode(e.target.value), required: true })] }), _jsx(ErrorLine, { message: error, className: c.error }), _jsx("button", { type: "submit", className: c.button, disabled: busy, children: unbroken(labels.signInWithCode ?? DEFAULT_AUTH_LABELS.signInWithCode) })] })), _jsx("button", { type: "button", className: c.buttonQuiet, onClick: () => {
|
|
setError(null);
|
|
setStep("start");
|
|
}, children: unbroken(labels.back) })] }));
|
|
}
|
|
if (step === "twoFactor") {
|
|
return (_jsxs("form", { onSubmit: withSecondFactor, className: c.stack, children: [_jsx("p", { className: c.hint, children: useBackup ? labels.backupPrompt : labels.totpPrompt }), _jsxs("div", { className: c.field, children: [_jsx("label", { htmlFor: "acct-code", className: c.label, children: useBackup ? labels.backupCode : labels.totpCode }), _jsx("input", { id: "acct-code", className: c.input, inputMode: useBackup ? "text" : "numeric", autoComplete: "one-time-code", value: code, onChange: (e) => setCode(e.target.value), required: true })] }), _jsxs("label", { className: c.check, children: [_jsx("input", { type: "checkbox", checked: trustDevice, onChange: (e) => setTrustDevice(e.target.checked) }), labels.trustDevice] }), _jsx(ErrorLine, { message: error, className: c.error }), _jsx("button", { type: "submit", className: c.button, disabled: busy, children: unbroken(labels.verify) }), _jsx("button", { type: "button", className: c.buttonQuiet, onClick: () => setUseBackup(!useBackup), children: unbroken(useBackup ? labels.useTotp : labels.useBackup) })] }));
|
|
}
|
|
return (_jsxs("div", { className: c.stack, children: [_jsx(OidcButtons, { client: client, methods: methods, labels: labels, classes: classes, callbackURL: next, errorCallbackURL: `${signInPath}?error=oidc&next=${encodeURIComponent(next)}`, onError: fail }), methods.passkey && (_jsx("button", { type: "button", className: c.buttonQuiet, onClick: withPasskey, disabled: busy, children: unbroken(labels.withPasskey) })), methods.lightning && client.lightning && (_jsx("button", { type: "button", className: c.buttonQuiet, onClick: () => {
|
|
setError(null);
|
|
setStep("lightning");
|
|
}, disabled: busy, children: unbroken(lightningWords(labels).withLightning) })), (hasOidc(methods) || methods.passkey || methods.lightning) && (_jsx(Divider, { label: labels.orEmail, className: c.divider })), _jsxs("form", { onSubmit: withPassword, className: c.stack, children: [_jsxs("div", { className: c.field, children: [_jsx("label", { htmlFor: "acct-email", className: c.label, children: labels.email }), _jsx("input", { id: "acct-email", type: "email", className: c.input, autoComplete: "username webauthn", value: email, onChange: (e) => setEmail(e.target.value), required: true })] }), _jsxs("div", { className: c.field, children: [_jsx("label", { htmlFor: "acct-password", className: c.label, children: labels.password }), _jsx("input", { id: "acct-password", type: "password", className: c.input, autoComplete: "current-password", value: password, onChange: (e) => setPassword(e.target.value), required: true })] }), _jsx(ErrorLine, { message: error, className: c.error }), unverified && methods.verifyEmail && (_jsx("button", { type: "button", className: c.buttonQuiet, onClick: resendVerification, disabled: busy, children: unbroken(labels.resendVerification) })), _jsx("button", { type: "submit", className: c.button, disabled: busy, children: unbroken(labels.signIn) }), methods.magicLink && (_jsx("button", { type: "button", className: c.buttonQuiet, onClick: withLink, disabled: busy, children: unbroken(labels.withLink) })), methods.passwordReset &&
|
|
client.requestPasswordReset &&
|
|
client.resetPassword && (_jsx("button", { type: "button", className: c.buttonQuiet, disabled: busy, onClick: () => setRecovery({}), children: unbroken((labels.recovery ?? DEFAULT_AUTH_LABELS.recovery).forgot) }))] }), _jsxs("p", { className: c.hint, children: [labels.noAccount, " ", signUpLink] })] }));
|
|
}
|
|
export { PasswordRecoveryForm } from "./recovery.js";
|
|
/**
|
|
* A new account in one step. No real name is asked for — a display name is
|
|
* optional and may be anything. A passkey is added from the account page once
|
|
* the account exists.
|
|
*/
|
|
export function SignUpForm({ client, methods, labels = DEFAULT_AUTH_LABELS, classes, next, signUpPath, signInPath = signUpPath.endsWith("/sign-up")
|
|
? signUpPath.replace(/sign-up$/, "sign-in")
|
|
: "/sign-in", signInLink, }) {
|
|
const c = merge(classes);
|
|
const [email, setEmail] = useState("");
|
|
const [password, setPassword] = useState("");
|
|
const [busy, setBusy] = useState(false);
|
|
const [error, setError] = useState(null);
|
|
const [sent, setSent] = useState(null);
|
|
const [lightning, setLightning] = useState(false);
|
|
const fail = (e) => {
|
|
setError(authErrorText(labels, e));
|
|
setBusy(false);
|
|
};
|
|
async function submit(event) {
|
|
event.preventDefault();
|
|
setError(null);
|
|
setBusy(true);
|
|
const { error: e } = await client.signUp.email({
|
|
// No name is asked for: an account starts nameless and the product
|
|
// shows the address until the person chooses one.
|
|
name: "",
|
|
email,
|
|
password,
|
|
callbackURL: next,
|
|
});
|
|
if (e)
|
|
return fail(e);
|
|
if (methods.verifyEmail) {
|
|
setSent("verify");
|
|
setBusy(false);
|
|
return;
|
|
}
|
|
window.location.assign(next);
|
|
}
|
|
async function withLink() {
|
|
if (!email)
|
|
return setError(labels.errors.emailFirst);
|
|
setBusy(true);
|
|
setError(null);
|
|
const { error: e } = await client.signIn.magicLink({
|
|
email,
|
|
callbackURL: next,
|
|
errorCallbackURL: `${signInPath}?method=magic-link&next=${encodeURIComponent(next)}`,
|
|
});
|
|
if (e)
|
|
return fail(e);
|
|
setSent("link");
|
|
setBusy(false);
|
|
}
|
|
if (sent) {
|
|
return (_jsx("p", { className: c.notice, role: "status", children: fill(sent === "verify" ? labels.confirmInbox : labels.checkInbox, {
|
|
email,
|
|
}) }));
|
|
}
|
|
if (lightning && client.lightning) {
|
|
return (_jsx(LightningLogin, { client: client.lightning, labels: labels, classes: c, purpose: "sign-in", onDone: () => window.location.assign(next),
|
|
// An existing account with a second factor finishes on sign-in.
|
|
onTwoFactor: () => window.location.assign(`${signInPath}?twoFactor=1&next=${encodeURIComponent(next)}`), onBack: () => setLightning(false) }));
|
|
}
|
|
return (_jsxs("div", { className: c.stack, children: [_jsx(OidcButtons, { client: client, methods: methods, labels: labels, classes: classes, callbackURL: next, errorCallbackURL: `${signInPath}?error=oidc&next=${encodeURIComponent(next)}`, onError: fail }), methods.lightning && client.lightning && (_jsx("button", { type: "button", className: c.buttonQuiet, onClick: () => setLightning(true), disabled: busy, children: unbroken(lightningWords(labels).withLightning) })), (hasOidc(methods) || methods.lightning) && (_jsx(Divider, { label: labels.orEmail, className: c.divider })), _jsxs("form", { onSubmit: submit, className: c.stack, children: [_jsxs("div", { className: c.field, children: [_jsx("label", { htmlFor: "acct-email", className: c.label, children: labels.email }), _jsx("input", { id: "acct-email", type: "email", className: c.input, autoComplete: "email", value: email, onChange: (e) => setEmail(e.target.value), required: true })] }), _jsxs("div", { className: c.field, children: [_jsx("label", { htmlFor: "acct-password", className: c.label, children: labels.password }), _jsx(PasswordField, { id: "acct-password", value: password, onChange: setPassword, classes: c, labels: labels })] }), _jsx(ErrorLine, { message: error, className: c.error }), _jsx("button", { type: "submit", className: c.button, disabled: busy, children: unbroken(labels.createAccount) }), methods.magicLink && (_jsx("button", { type: "button", className: c.buttonQuiet, onClick: withLink, disabled: busy, children: unbroken(labels.signUpWithLink) }))] }), _jsxs("p", { className: c.hint, children: [labels.haveAccount, " ", signInLink] })] }));
|
|
}
|
|
function Section({ title, id, classes, children, }) {
|
|
return (_jsxs("section", { className: classes.section, "aria-labelledby": id, children: [_jsx("h2", { id: id, className: classes.sectionTitle, children: title }), children] }));
|
|
}
|
|
/** Everything about one's own account, and the way out of it. */
|
|
export function AccountPanel({ client, methods, labels = DEFAULT_AUTH_LABELS, classes, user, linked, accountPath, homePath, deletion, ownProfile = false, }) {
|
|
const c = merge(classes);
|
|
const a = labels.account;
|
|
const [error, setError] = useState(null);
|
|
const [busy, setBusy] = useState(false);
|
|
const [name, setName] = useState(user.name);
|
|
const [saved, setSaved] = useState(false);
|
|
const [passkeys, setPasskeys] = useState(null);
|
|
const [totp, setTotp] = useState(null);
|
|
const [code, setCode] = useState("");
|
|
const [password, setPassword] = useState("");
|
|
const [twoFactor, setTwoFactor] = useState(user.twoFactorEnabled);
|
|
const [confirmDelete, setConfirmDelete] = useState("");
|
|
const fail = (e) => {
|
|
setError(authErrorText(labels, e) ?? labels.errors.generic);
|
|
setBusy(false);
|
|
};
|
|
const loadPasskeys = useCallback(async () => {
|
|
const { data } = await client.passkey.listUserPasskeys();
|
|
setPasskeys(data ?? []);
|
|
}, [client]);
|
|
useEffect(() => {
|
|
let alive = true;
|
|
void client.passkey.listUserPasskeys().then(({ data }) => {
|
|
if (alive)
|
|
setPasskeys(data ?? []);
|
|
});
|
|
return () => {
|
|
alive = false;
|
|
};
|
|
}, [client]);
|
|
async function saveName(event) {
|
|
event.preventDefault();
|
|
setBusy(true);
|
|
setError(null);
|
|
const { error: e } = await client.updateUser({ name: name.trim() });
|
|
if (e)
|
|
return fail(e);
|
|
setSaved(true);
|
|
setBusy(false);
|
|
}
|
|
async function addPasskey() {
|
|
setBusy(true);
|
|
setError(null);
|
|
const result = await client.passkey.addPasskey({
|
|
name: a.passkeyDefaultName,
|
|
});
|
|
if (result?.error)
|
|
return fail(result.error);
|
|
await loadPasskeys();
|
|
setBusy(false);
|
|
}
|
|
async function removePasskey(id) {
|
|
setBusy(true);
|
|
const { error: e } = await client.passkey.deletePasskey({ id });
|
|
if (e)
|
|
return fail(e);
|
|
await loadPasskeys();
|
|
setBusy(false);
|
|
}
|
|
async function startTwoFactor() {
|
|
setBusy(true);
|
|
setError(null);
|
|
const { data, error: e } = await client.twoFactor.enable({
|
|
password: password || undefined,
|
|
});
|
|
if (e)
|
|
return fail(e);
|
|
if (!data || !("totpURI" in data))
|
|
return fail({});
|
|
const setup = data;
|
|
setTotp({ uri: setup.totpURI, backupCodes: setup.backupCodes });
|
|
setBusy(false);
|
|
}
|
|
async function confirmTwoFactor(event) {
|
|
event.preventDefault();
|
|
setBusy(true);
|
|
const { error: e } = await client.twoFactor.verifyTotp({
|
|
code: code.trim(),
|
|
});
|
|
if (e)
|
|
return fail(e);
|
|
setTwoFactor(true);
|
|
setTotp(null);
|
|
setCode("");
|
|
setBusy(false);
|
|
}
|
|
async function stopTwoFactor() {
|
|
setBusy(true);
|
|
setError(null);
|
|
const { error: e } = await client.twoFactor.disable({
|
|
password: password || undefined,
|
|
});
|
|
if (e)
|
|
return fail(e);
|
|
setTwoFactor(false);
|
|
setBusy(false);
|
|
}
|
|
async function link(provider) {
|
|
setBusy(true);
|
|
const { error: e } = await client.linkSocial({
|
|
provider,
|
|
callbackURL: accountPath,
|
|
});
|
|
if (e)
|
|
fail(e);
|
|
}
|
|
async function signOut() {
|
|
await client.signOut();
|
|
window.location.assign(homePath);
|
|
}
|
|
async function deleteAccount() {
|
|
setBusy(true);
|
|
const { error: e } = await client.deleteUser({
|
|
password: password || undefined,
|
|
});
|
|
if (e)
|
|
return fail(e);
|
|
window.location.assign(homePath);
|
|
}
|
|
const oidc = [
|
|
{
|
|
id: "bitbaum-signin",
|
|
label: signinButtonLabel(labels, methods.signinProviders),
|
|
on: methods.signin,
|
|
},
|
|
{ id: "orangecat", label: labels.withOrangecat, on: methods.orangecat },
|
|
{
|
|
id: "github",
|
|
label: labels.withGithub ?? DEFAULT_AUTH_LABELS.withGithub,
|
|
on: Boolean(methods.github),
|
|
},
|
|
];
|
|
const methodName = (id) => id === "credential"
|
|
? a.methodPassword
|
|
: id === "lightning"
|
|
? lightningWords(labels).name
|
|
: (oidc.find((o) => o.id === id)?.label ?? id);
|
|
const [linkingLightning, setLinkingLightning] = useState(false);
|
|
return (_jsxs("div", { className: c.stack, children: [_jsx(ErrorLine, { message: error, className: c.error }), !ownProfile && (_jsx(Section, { title: a.profile, id: "acct-profile", classes: c, children: _jsxs("form", { onSubmit: saveName, className: c.stack, children: [_jsxs("div", { className: c.field, children: [_jsx("label", { htmlFor: "acct-display-name", className: c.label, children: labels.displayName }), _jsx("input", { id: "acct-display-name", className: c.input, maxLength: 80, value: name, onChange: (e) => {
|
|
setName(e.target.value);
|
|
setSaved(false);
|
|
} })] }), _jsxs("dl", { className: c.hint, children: [_jsxs("div", { children: [_jsxs("dt", { style: { display: "inline" }, children: [labels.email, ": "] }), _jsxs("dd", { style: { display: "inline", margin: 0 }, children: [user.email ?? a.noEmail, user.email && !user.emailVerified && ` (${a.unverified})`] })] }), _jsxs("div", { children: [_jsxs("dt", { style: { display: "inline" }, children: [a.role, ": "] }), _jsx("dd", { style: { display: "inline", margin: 0 }, children: a.roles[user.role] ?? user.role })] })] }), _jsxs("div", { children: [_jsx("button", { type: "submit", className: c.button, disabled: busy, children: unbroken(a.save) }), " ", saved && _jsx("span", { role: "status", children: a.saved })] })] }) })), _jsxs(Section, { title: a.methods, id: "acct-methods", classes: c, children: [_jsx("ul", { className: c.hint, children: linked.map((id) => (_jsx("li", { children: methodName(id) }, id))) }), _jsxs("div", { className: c.stack, children: [oidc
|
|
.filter((o) => o.on && !linked.includes(o.id))
|
|
.map((o) => (_jsx("button", { type: "button", className: c.buttonQuiet, onClick: () => link(o.id), disabled: busy, children: unbroken(fill(a.link, { method: o.label })) }, o.id))), methods.lightning &&
|
|
client.lightning &&
|
|
!linked.includes("lightning") &&
|
|
(linkingLightning ? (_jsx(LightningLogin, { client: client.lightning, labels: labels, classes: c, purpose: "link", onDone: () => window.location.reload(), onBack: () => setLinkingLightning(false) })) : (_jsx("button", { type: "button", className: c.buttonQuiet, onClick: () => setLinkingLightning(true), disabled: busy, children: unbroken(fill(a.link, { method: lightningWords(labels).name })) })))] })] }), _jsxs(Section, { title: a.passkeys, id: "acct-passkeys", classes: c, children: [_jsx("p", { className: c.hint, children: a.passkeysLede }), passkeys && passkeys.length > 0 && (_jsx("ul", { className: c.stack, children: passkeys.map((p) => (_jsxs("li", { children: [_jsx("span", { children: p.name || a.passkeyDefaultName }), " ", _jsx("button", { type: "button", className: c.buttonQuiet, onClick: () => removePasskey(p.id), disabled: busy, children: unbroken(a.remove) })] }, p.id))) })), _jsx("button", { type: "button", className: c.button, onClick: addPasskey, disabled: busy, children: unbroken(a.addPasskey) })] }), _jsxs(Section, { title: a.twoFactor, id: "acct-two-factor", classes: c, children: [_jsx("p", { className: c.hint, children: twoFactor ? a.twoFactorOn : a.twoFactorOff }), _jsxs("div", { className: c.field, children: [_jsx("label", { htmlFor: "acct-current-password", className: c.label, children: a.currentPassword }), _jsx("input", { id: "acct-current-password", type: "password", className: c.input, autoComplete: "current-password", value: password, onChange: (e) => setPassword(e.target.value), "aria-describedby": "acct-current-password-hint" }), _jsx("p", { id: "acct-current-password-hint", className: c.hint, children: a.currentPasswordHint })] }), totp ? (_jsxs("form", { onSubmit: confirmTwoFactor, className: c.stack, children: [_jsx("p", { className: c.notice, children: a.scan }), _jsx("a", { href: totp.uri, className: c.link, children: a.openAuthenticator }), _jsx("p", { className: c.hint, children: a.backupCodes }), _jsx("ul", { className: c.hint, children: totp.backupCodes.map((backup) => (_jsx("li", { children: _jsx("code", { children: backup }) }, backup))) }), _jsxs("div", { className: c.field, children: [_jsx("label", { htmlFor: "acct-totp", className: c.label, children: labels.totpCode }), _jsx("input", { id: "acct-totp", className: c.input, inputMode: "numeric", autoComplete: "one-time-code", value: code, onChange: (e) => setCode(e.target.value), required: true })] }), _jsx("button", { type: "submit", className: c.button, disabled: busy, children: unbroken(a.turnOn) })] })) : twoFactor ? (_jsx("button", { type: "button", className: c.buttonQuiet, onClick: stopTwoFactor, disabled: busy, children: unbroken(a.turnOff) })) : (_jsx("button", { type: "button", className: c.button, onClick: startTwoFactor, disabled: busy, children: unbroken(a.setUp) }))] }), _jsx(Section, { title: a.leave, id: "acct-leave", classes: c, children: _jsxs("div", { className: c.stack, children: [_jsx("button", { type: "button", className: c.buttonQuiet, onClick: signOut, children: unbroken(a.signOut) }), deletion ?? (_jsxs(_Fragment, { children: [_jsxs("div", { className: c.field, children: [_jsx("label", { htmlFor: "acct-confirm-delete", className: c.label, children: fill(a.deleteConfirm, { word: a.deleteWord }) }), _jsx("input", { id: "acct-confirm-delete", className: c.input, value: confirmDelete, onChange: (e) => setConfirmDelete(e.target.value) })] }), _jsx("button", { type: "button", className: c.buttonQuiet, onClick: deleteAccount, disabled: busy ||
|
|
confirmDelete.trim().toLowerCase() !==
|
|
a.deleteWord.toLowerCase(), children: unbroken(a.delete) })] }))] }) })] }));
|
|
}
|
|
export { DEFAULT_AUTH_LABELS, authErrorText, fill, };
|
|
//# sourceMappingURL=react.js.map
|