Say why a sign-in link didn't work, and clear rejected sign-ins

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
minimus7andClaude Opus 5.5 committed 2026-11-04 12:04:13 -06:00
1 parent de40f85407
commit 9c4bf6198e
4 files changed
+11 -2

No files matched your search

+1
View File
@@ -8,6 +8,7 @@ export async function GET(request: Request) {
const supabase = await createClient(); const supabase = await createClient();
const { error } = await supabase.auth.exchangeCodeForSession(code); const { error } = await supabase.auth.exchangeCodeForSession(code);
if (!error) return home(origin); if (!error) return home(origin);
console.error("[broke] sign-in link:", error.message);
} }
return NextResponse.redirect(`${origin}/login?error=link`); return NextResponse.redirect(`${origin}/login?error=link`);
} }
+4
View File
@@ -11,6 +11,10 @@ export default function LoginPage() {
const [firstRun, setFirstRun] = useState<string | null>(null); const [firstRun, setFirstRun] = useState<string | null>(null);
const [devLogin, setDevLogin] = useState(false); const [devLogin, setDevLogin] = useState(false);
useEffect(() => { useEffect(() => {
if (new URLSearchParams(window.location.search).get("error") === "link") {
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.");
}
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);
setDevLogin(!!b.devLogin); setDevLogin(!!b.devLogin);
+2 -1
View File
@@ -3,6 +3,7 @@ import { updateSession } from "@/utils/supabase/middleware";
export const middleware = (request: NextRequest) => updateSession(request); export const middleware = (request: NextRequest) => updateSession(request);
// auth/callback runs without the session refresh: clearing an old sign-in there would wipe the one the email link just made.
export const config = { export const config = {
matcher: ["/((?!_next/static|_next/image|favicon.ico|api/plaid/webhook|api/agent|api/ai/helper|broke-connect|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)"], matcher: ["/((?!_next/static|_next/image|favicon.ico|api/plaid/webhook|auth/callback|api/agent|api/ai/helper|broke-connect|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)"],
}; };
+4 -1
View File
@@ -47,7 +47,10 @@ export async function updateSession(request: NextRequest) {
if (!user && !path.startsWith("/login") && !path.startsWith("/auth")) { if (!user && !path.startsWith("/login") && !path.startsWith("/auth")) {
const url = request.nextUrl.clone(); const url = request.nextUrl.clone();
url.pathname = "/login"; url.pathname = "/login";
return NextResponse.redirect(url); // Keep the cookie changes getClaims made: a sign-in Supabase no longer accepts gets cleared here, not resent forever.
const to = NextResponse.redirect(url);
response.cookies.getAll().forEach((c) => to.cookies.set(c));
return to;
} }
// Signed in but no bank keys yet: app pages would be empty, so show the checklist instead. // Signed in but no bank keys yet: app pages would be empty, so show the checklist instead.
if (user && !path.startsWith("/api") && !(isSet(process.env.PLAID_CLIENT_ID) && isSet(process.env.PLAID_SECRET))) return toSetup(request); if (user && !path.startsWith("/api") && !(isSet(process.env.PLAID_CLIENT_ID) && isSet(process.env.PLAID_SECRET))) return toSetup(request);