>>> yup for email & url validation, fixed minor err in error msgs

This commit is contained in:
Joel Biddle
2023-08-24 12:59:24 +10:00
parent 7ec00475c6
commit 368855a44e
13 changed files with 61 additions and 9 deletions
@@ -46,6 +46,7 @@ type Errors = {
specialChar?: string;
repeatedChar?: string;
isEmail?: string;
isUrl?: string;
isBeachedPassword?: string;
};
@@ -1,4 +1,4 @@
import isEmail from "validator/lib/isEmail";
import {string} from "yup";
import { checkIsPasswordBreached } from "./checkIsPasswordBreached";
/* eslint-disable no-param-reassign */
@@ -13,6 +13,7 @@ interface PasswordCheckProps {
setPasswordErrorSpecialChar: (value: boolean) => void;
setPasswordErrorRepeatedChar: (value: boolean) => void;
setPasswordErrorIsEmail: (value: boolean) => void;
setPasswordErrorIsUrl: (value: boolean) => void;
setPasswordErrorIsBreachedPassword: (value: boolean) => void;
}
@@ -29,6 +30,7 @@ const passwordCheck = async ({
setPasswordErrorSpecialChar,
setPasswordErrorRepeatedChar,
setPasswordErrorIsEmail,
setPasswordErrorIsUrl,
setPasswordErrorIsBreachedPassword,
errorCheck
}: PasswordCheckProps) => {
@@ -97,13 +99,25 @@ const passwordCheck = async ({
}
// isEmail
if (isEmail(password)) {
const emailSchema = string().email();
if (await emailSchema.isValid(password)) {
setPasswordErrorIsEmail(true);
errorCheck = true;
} else {
setPasswordErrorIsEmail(false);
}
// isUrl
const urlSchema = string().url();
if (await urlSchema.isValid(password)) {
setPasswordErrorIsUrl(true);
errorCheck = true;
} else {
setPasswordErrorIsUrl(false);
}
// breachedPassword
if (await checkIsPasswordBreached(password)) {
setPasswordErrorIsBreachedPassword(true);
@@ -1,4 +1,4 @@
import isEmail from "validator/lib/isEmail";
import {string} from "yup"
import { checkIsPasswordBreached } from "./checkIsPasswordBreached";
type Errors = {
@@ -10,6 +10,7 @@ type Errors = {
specialChar?: string;
repeatedChar?: string;
isEmail?: string;
isUrl?: string;
isBreachedPassword?: string;
};
@@ -93,10 +94,19 @@ const checkPassword = async ({ password, setErrors }: CheckPasswordParams): Prom
}
// isEmail
if (isEmail(password)) {
const emailSchema = string().email();
if (await emailSchema.isValid(password)) {
errors.isEmail = "The password cannot be an email address";
}
// isUrl
const urlSchema = string().url();
if (await urlSchema.isValid(password)) {
errors.isUrl = "The password cannot be a URL";
}
// breachedPassword
if (await checkIsPasswordBreached(password)) {
errors.isBreachedPassword =