forked from fahrPool/fahrPool
24 lines
779 B
TypeScript
24 lines
779 B
TypeScript
export type LoginInput = {
|
|
email: FormDataEntryValue | null;
|
|
password: FormDataEntryValue | null;
|
|
};
|
|
|
|
export type LoginValidationResult =
|
|
| { valid: true; email: string; password: string }
|
|
| { valid: false; error: string };
|
|
|
|
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
|
|
export function validateLogin(input: LoginInput): LoginValidationResult {
|
|
const email = typeof input.email === "string" ? input.email.trim() : "";
|
|
const password = typeof input.password === "string" ? input.password : "";
|
|
|
|
if (!email || !EMAIL_REGEX.test(email)) {
|
|
return { valid: false, error: "Bitte eine gültige E-Mail-Adresse eingeben." };
|
|
}
|
|
if (!password) {
|
|
return { valid: false, error: "Bitte ein Passwort eingeben." };
|
|
}
|
|
return { valid: true, email, password };
|
|
}
|