/>`;
}
if (cloud.user) {
return html`<${Account} onDone=${onDone} />`;
}
const submit = async (event) => {
event.preventDefault();
setError("");
setMessage("");
setBusy(true);
try {
if (mode === "signin") await cloud.signIn(email.trim(), password);
else {
const result = await cloud.signUp(email.trim(), password);
if (result && result.session) setMessage("Account created. You are signed in.");
else setMessage("Account created. Check your email — the link signs you straight in, or paste the six-digit code below.");
}
} catch (err) {
setError(err && err.message ? err.message : "That did not work.");
}
setBusy(false);
};
const sendLink = async () => {
setError("");
setMessage("");
if (!email.trim()) {
setError("Type your email first.");
return;
}
setBusy(true);
try {
await cloud.magicLink(email.trim());
setMessage("A sign-in link is on its way to " + email.trim() + ".");
} catch (err) {
setError(err && err.message ? err.message : "The link could not be sent.");
}
setBusy(false);
};
const forgot = async () => {
setError("");
setMessage("");
if (!email.trim()) {
setError("Type your email first, then press Forgot password.");
return;
}
setBusy(true);
try {
await cloud.resetPassword(email.trim());
setMessage("If " + email.trim() + " has an account, a reset link is on its way. It signs you in so you can choose a new password.");
} catch (err) {
setError(err && err.message ? err.message : "The reset email could not be sent.");
}
setBusy(false);
};
const submitCode = async (event) => {
event.preventDefault();
setError("");
setMessage("");
if (!email.trim()) {
setError("Type your email first, then the code.");
return;
}
if (!/^\d{6}$/.test(code.trim())) {
setError("The code is six digits.");
return;
}
setBusy(true);
try {
await cloud.verifyCode(email.trim(), code.trim());
setMessage("Code accepted. You're signed in.");
} catch (err) {
setError(err && err.message ? err.message : "That code did not work.");
}
setBusy(false);
};
return html`<${Shell}>
Account
${mode === "signin" ? "Welcome back." : "Make an account."}
An account keeps your plan, your model budget and any downloads you own. Your writing still stays in this browser.
No password? Send a one-time link instead.
Got a six-digit code in the email?
${showCode && html``}
Plans and purchases are attached to this account. You can use every marking tool without one.
/>`;
}
// ---------------------------------------------------------------------------
// Account / plan
// ---------------------------------------------------------------------------
function BudgetBar({ budget, plan }) {
if (!plan) return null;
if (!plan.cost_limit_cents) {
return html`
This pack is all offline: download the models and they are yours, with no allowance to run down.
Add an OpenAI-compatible endpoint in Settings and every hosted feature runs on your own key. It never touches your included allowance, so you can keep going as long as you like.
`}
/>`;
}
// ---------------------------------------------------------------------------
// Landing screens for email links
// ---------------------------------------------------------------------------
const WELCOME_COPY = {
signup: {
eyebrow: "Account confirmed",
title: "You're in.",
body: "Your email is confirmed and you're signed in. Your plan, budget and downloads stay with this account."
},
magiclink: {
eyebrow: "Signed in",
title: "You're signed in.",
body: "The link worked — no password needed."
},
email_change: {
eyebrow: "Address updated",
title: "That's your new address.",
body: "Your sign-in address has changed, and you're already signed in with it."
},
session: {
eyebrow: "Signed in",
title: "You're in.",
body: "The link worked and you're signed in."
}
};
function CentredCard({ children }) {
return html`
${children}
`;
}
function Tick({ tone = "good" }) {
const good = tone === "good";
return html`
/>
/>`;
}
// Where a password-reset or invite link lands. The link has already signed the
// person in; this screen is the missing step that sets the password.
export function NewPassword({ kind, onDone }) {
const cloud = useCloud();
const [password, setPassword] = useState("");
const [again, setAgain] = useState("");
const [busy, setBusy] = useState(false);
const [done, setDone] = useState(false);
const [error, setError] = useState("");
const submit = async (event) => {
event.preventDefault();
setError("");
if (password.length < 6) {
setError("Use at least six characters.");
return;
}
if (password !== again) {
setError("The two passwords don't match.");
return;
}
setBusy(true);
try {
await cloud.updatePassword(password);
setDone(true);
} catch (err) {
setError(err && err.message ? err.message : "The password could not be changed.");
}
setBusy(false);
};
if (!cloud.ready) {
return html`<${Shell}><${Waiting} />/>`;
}
if (!cloud.configured) {
return html`<${Shell}>
<${CentredCard}>
<${Tick} tone="bad" />
No accounts yet.
This copy of the site has no Supabase project, so there is no password to change.
${kind === "invite" ? "Choose a password." : "Choose a new password."}
${kind === "invite" ? "Set a password for " + cloud.user.email + " and you're in." : "You're signed in as " + cloud.user.email + ". Pick something you'll remember."}
/>
/>`;
}
// When Supabase itself reports the link is bad or used.
export function LinkProblem({ onDone }) {
return html`<${Shell}>
<${CentredCard}>
<${Tick} tone="bad" />
That link has expired.
Email links work once and last an hour. Ask for a fresh one from the sign-in page — it takes a moment.
<${Notice} kind="info">
Two things left in the Supabase dashboard: run the SQL in supabase/schema.sql in the SQL editor, then paste the same URL and key into js/config.js so every visitor gets them automatically.
/>
This setup screen disappears from the site once a project is connected. It stays available in Developer → Supabase.
/>`;
}
return html`<${Shell}>
Setup
Connect Supabase.
Supabase holds the accounts, the plans, the shared page wording and the model budgets. Create a free project, then paste two values from Project Settings → API.
Only the anon public key goes in the browser. It is safe to publish: row-level security in the schema stops anyone but ${DEVELOPER_EMAIL} from changing plans, models or wording. Never paste the service_role key here.