Trim emails before validating them

Zod ran the email format check before trim, so an address with a trailing
space was rejected as invalid. iOS keyboards commonly add one after
autocomplete.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MzFywujuH9TiuXbr9vjoX8
This commit is contained in:
2026-10-03 11:28:17 -04:00
co-authored by Claude Opus 5.5
parent 1559da60f5
commit 0122a93212
+5 -2
View File
@@ -7,14 +7,17 @@ export const usernameSchema = z
.toLowerCase()
.regex(/^[a-z0-9_]{3,32}$/, 'Username must be 3-32 characters: letters, numbers, underscores');
// Trim before validating: iOS keyboards often append a space after autocompleting an email.
const emailSchema = z.string().trim().toLowerCase().pipe(z.email());
export const registerSchema = z.object({
username: usernameSchema,
email: z.email().trim().toLowerCase(),
email: emailSchema,
password: z.string().min(8, 'Password must be at least 8 characters').max(200),
});
export const loginSchema = z.object({
email: z.email().trim().toLowerCase(),
email: emailSchema,
password: z.string().min(1).max(200),
});