I am using yup and yup-password to validate password creation on my app and ran into a problem when validating New Password against Current Password. I needed to find a way to throw an error if the new password matches the existing one.
I had a bit of a hard time finding this answered anywhere, so I thought I'd create this issue and answer it myself. Hope it helps someone!
Came across this function on yup documentation, and here's the implementation:
const newPasswordField = () =>
passwordField().notOneOf(
[Yup.ref('currentPassword'), null],
'passwords must be different'
);
When the newPassword matches currentPassword, an error is thrown with the message 'passwords must be different'.