Add validation to date_of_birth registration field

Resolves: #1020
This commit is contained in:
Zane Helton 2025-06-27 22:23:10 -04:00 committed by Madeline
parent ac1779b480
commit c0f9c22e67

View File

@ -206,10 +206,24 @@ router.post(
minimum.setFullYear(
minimum.getFullYear() - register.dateOfBirth.minimum,
);
body.date_of_birth = new Date(body.date_of_birth as Date);
let parsedDob;
try {
parsedDob = new Date(body.date_of_birth as Date);
if (isNaN(parsedDob.getTime())) {
throw new Error("Invalid date");
}
} catch (e) {
throw FieldErrors({
date_of_birth: {
code: "DATE_OF_BIRTH_INVALID",
message: req.t("auth:register.DATE_OF_BIRTH_INVALID"),
},
});
}
// higher is younger
if (body.date_of_birth > minimum) {
if (parsedDob > minimum) {
throw FieldErrors({
date_of_birth: {
code: "DATE_OF_BIRTH_UNDERAGE",