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:
+20
-2
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user