const RegisterSchema = v.pipe(
v.object({
email: v.pipe(
v.string(),
v.nonEmpty('Please enter your email.'),
v.email('The email address is badly formatted.')
),
password1: v.pipe(
v.string(),
v.nonEmpty('Please enter your password.'),
v.minLength(8, 'Your password must have 8 characters or more.')
),
password2: v.string(),
}),
v.forward(
v.check((input) => input.password1 === input.password2, 'The two passwords do not match.'),
['password2']
)
)
If there isn't an error in the password1 property and you pass in a non-matching password2 property, the flatten output is as expected
Using the following schema
If there isn't an error in the password1 property and you pass in a non-matching password2 property, the flatten output is as expected
But, if there is an error in the password1 property, the flattened output becomes
Below is the entire code to reproduce with a copy paste