
Making Shop Auth Accept Phone OR Email — A zod + TypeScript Fix
Users wanted to register with just a phone number, but the backend required an email. A small bug with real impact. Background Our LINE-integrated e-commerce site targets users who often do not have or do not want to enter an email address. The registration form said just enter your phone number, but submitting it returned 400 Bad Request . The cause was simple: the frontend was sending only phone , but the backend validation had email: required . What We Changed Frontend (Vue + Vite) Changed the email field to optional: <input v-model= "form.email" type= "email" placeholder= "Email (optional)" /> Removed the email-required check from client-side validation. Backend (Node.js / ts-node) Fixed the /api/auth/register endpoint validation: // Before const schema = z . object ({ phone : z . string (), email : z . string (). email (), // The problem password : z . string (). min ( 6 ), }); // After const schema = z . object ({ phone : z . string (). optional (), email : z . string (). email (
Continue reading on Dev.to Webdev
Opens in a new tab


