Detect checkout email collisions and show login state in the navbar

Registering with an email that already has an account previously just
failed with a generic error and no clear next step. registerCustomer()
now flags emailExists specifically, and checkout switches straight to the
login toggle (email pre-filled, scrolled into view) instead. The account
icon also gets a small underline while logged in, matching the nav links'
active-state styling — it was otherwise the only nav element that gave no
visual signal of session state.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Marco
2026-07-22 08:26:00 +00:00
parent f0df359db4
commit ec75a480bd
4 changed files with 58 additions and 6 deletions
+20 -2
View File
@@ -39,7 +39,9 @@ export type CustomerSummary = {
emailVerified: boolean;
};
export type AuthResult = { ok: true; token: string; customer: CustomerSummary } | { ok: false; reason: string };
export type AuthResult =
| { ok: true; token: string; customer: CustomerSummary }
| { ok: false; reason: string; emailExists?: boolean };
export async function registerCustomer(input: {
firstName: string;
@@ -58,7 +60,23 @@ export async function registerCustomer(input: {
if (!res.ok) {
const data = await res.json().catch(() => null);
const message: string | undefined = data?.errors?.[0]?.message;
return { ok: false, reason: message ?? "Diese E-Mail-Adresse ist bereits registriert." };
// Payload's own message for a duplicate unique field is a generic
// "The following field is invalid: email" — not distinguishable from
// any other email-field validation failure by content alone, but at
// this point the client's own type="email" + required already ruled
// out a malformed/missing address, so "email" being the flagged field
// here in practice only ever means one thing: this address is already
// registered. emailExists lets the checkout UI react to that
// specifically (switch to the login toggle) instead of just showing
// an error the customer has no clear next step for.
const emailExists = Boolean(message?.toLowerCase().includes("email"));
return {
ok: false,
reason: emailExists
? "Diese E-Mail-Adresse ist bereits registriert. Bitte logge dich stattdessen ein."
: (message ?? "Registrierung ist gerade nicht möglich."),
emailExists,
};
}
return loginCustomer(input);