Sign-in page: don't promise a code when the email has a link

Supabase's default sign-in email has only a link; the code appears only after
the email template is changed. The page said "Sign in with a code" and
"Send code" either way. It now says Send sign-in email, then: open the link
in this browser, or type the code if the email has one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
minimus7andClaude Opus 5.5 committed 2026-11-10 21:40:10 -06:00
1 parent b7dc3a6f57
commit 3e51cc4fcc
1 file changed
+8 -8
+8 -8
View File
@@ -17,7 +17,7 @@ export default function LoginPage() {
useEffect(() => { useEffect(() => {
if (new URLSearchParams(window.location.search).get("error") === "link") { if (new URLSearchParams(window.location.search).get("error") === "link") {
setState("error"); setState("error");
setMessage("That sign-in link didn't work. Each link works once, for about an hour, in the browser you asked for it from. Send a new one."); setMessage("That sign-in link didn't work. Each link works once, for about an hour, and only in the browser you asked for it from. Send a new email and open its link here.");
} }
fetch("/api/setup/first-run").then((r) => r.json()).then((b: { supabase?: string; devLogin?: boolean }) => { fetch("/api/setup/first-run").then((r) => r.json()).then((b: { supabase?: string; devLogin?: boolean }) => {
setFirstRun(b.supabase ?? null); setFirstRun(b.supabase ?? null);
@@ -34,7 +34,7 @@ export default function LoginPage() {
}); });
if (error) { if (error) {
setState("error"); setState("error");
setMessage(/rate limit|too many/i.test(error.message) ? "Too many sign-in emails for now. Supabase's free email sends a few an hour. Wait a bit, or use the code or link from the last email." : error.message); setMessage(/rate limit|too many/i.test(error.message) ? "Too many sign-in emails for now. Supabase's free email sends a few an hour. Wait a bit, or use the link from the last email." : error.message);
} else { } else {
setSent(true); setSent(true);
setCode(""); setCode("");
@@ -49,7 +49,7 @@ export default function LoginPage() {
if (error) { if (error) {
setState("error"); setState("error");
setCode(""); // ready for the right one, not mixed in with the wrong one setCode(""); // ready for the right one, not mixed in with the wrong one
setMessage(/expired|invalid/i.test(error.message) ? "That code didn't work. Codes work once, for about an hour. Check you typed the newest one, or send a new one." : error.message); setMessage(/expired|invalid/i.test(error.message) ? "That code didn't work. Codes work once, for about an hour. Check you typed the newest one, or send a new email." : error.message);
} else window.location.assign("/"); // a full load: the page cache may still hold "/" from before sign-in (a redirect back here) } else window.location.assign("/"); // a full load: the page cache may still hold "/" from before sign-in (a redirect back here)
} }
@@ -69,10 +69,11 @@ export default function LoginPage() {
<form onSubmit={sent ? verify : send} className="card p-8 space-y-5"> <form onSubmit={sent ? verify : send} className="card p-8 space-y-5">
<div> <div>
<Logo /> <Logo />
<p className="text-sm text-muted mt-1">{sent ? `We sent a code to ${email}.` : "Sign in with a code sent to your email."}</p> <p className="text-sm text-muted mt-1">{sent ? `We sent an email to ${email}.` : "Sign in with your email."}</p>
</div> </div>
{sent ? ( {sent ? (
<> <>
<p className="text-sm">Open the sign-in link in that email, in this browser. Or, if the email has a code, type it here.</p>
<input <input
inputMode="numeric" inputMode="numeric"
autoComplete="one-time-code" autoComplete="one-time-code"
@@ -80,7 +81,7 @@ export default function LoginPage() {
autoFocus autoFocus
value={code} value={code}
onChange={(e) => setCode(e.target.value.replace(/[^\d\s]/g, ""))} onChange={(e) => setCode(e.target.value.replace(/[^\d\s]/g, ""))}
placeholder="Code from the email" placeholder="Code"
aria-label="Code from the email" aria-label="Code from the email"
className="input w-full tabular tracking-[0.2em] text-center text-lg" className="input w-full tabular tracking-[0.2em] text-center text-lg"
/> />
@@ -88,9 +89,8 @@ export default function LoginPage() {
{state === "checking" ? "Checking..." : "Sign in"} {state === "checking" ? "Checking..." : "Sign in"}
</button> </button>
{state === "error" && <p className="text-sm text-red-600">{message}</p>} {state === "error" && <p className="text-sm text-red-600">{message}</p>}
<p className="text-xs text-muted">No code in the email? Click its sign-in link instead, in this browser.</p>
<div className="flex justify-between text-sm"> <div className="flex justify-between text-sm">
<button type="button" onClick={() => send()} disabled={state === "sending"} className="text-muted underline underline-offset-4">{state === "sending" ? "Sending..." : "Send a new code"}</button> <button type="button" onClick={() => send()} disabled={state === "sending"} className="text-muted underline underline-offset-4">{state === "sending" ? "Sending..." : "Send a new email"}</button>
<button type="button" onClick={() => { setSent(false); setState("idle"); }} className="text-muted underline underline-offset-4">Use another email</button> <button type="button" onClick={() => { setSent(false); setState("idle"); }} className="text-muted underline underline-offset-4">Use another email</button>
</div> </div>
</> </>
@@ -106,7 +106,7 @@ export default function LoginPage() {
className="input w-full" className="input w-full"
/> />
<button disabled={state === "sending"} className="btn-primary w-full"> <button disabled={state === "sending"} className="btn-primary w-full">
{state === "sending" ? "Sending..." : "Send code"} {state === "sending" ? "Sending..." : "Send sign-in email"}
</button> </button>
{state === "error" && <p className="text-sm text-red-600">{message}</p>} {state === "error" && <p className="text-sm text-red-600">{message}</p>}
{devLogin && ( {devLogin && (