mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 02:51:51 +00:00
>>> yup for email & url validation, fixed minor err in error msgs
This commit is contained in:
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user