()
| 14 | const PASSWORD_LENGTH_MAX_LIMIT = 126 |
| 15 | |
| 16 | const SignupForm: FC = () => { |
| 17 | const { |
| 18 | onSignupSuccess, |
| 19 | onSignupError, |
| 20 | onGoogleSignupSucess, |
| 21 | onGoogleSignupError, |
| 22 | setAuthDialogState, |
| 23 | } = useContext(AuthContext); |
| 24 | |
| 25 | const handleGoogleSignIn = () => { |
| 26 | authService.signUpWithGoogle(onGoogleSignupSucess, onGoogleSignupError); |
| 27 | }; |
| 28 | |
| 29 | const formSchema = z.object({ |
| 30 | email: z.string({ |
| 31 | required_error: "Email is required", |
| 32 | invalid_type_error: "Email should be a string" |
| 33 | }).email("Invalid email address"), |
| 34 | password: z.string({ |
| 35 | required_error: "Password is required", |
| 36 | invalid_type_error: "Password should be a string" |
| 37 | }).min(PASSWORD_LENGTH_MIN_LIMIT, `Password length should be at least ${PASSWORD_LENGTH_MIN_LIMIT} characters`) |
| 38 | .max(PASSWORD_LENGTH_MAX_LIMIT, `Password cannot exceed more than ${PASSWORD_LENGTH_MAX_LIMIT} characters`), |
| 39 | confirm_password: z.string({ |
| 40 | required_error: "Confirm Password is required", |
| 41 | invalid_type_error: "Confirm Password should be a string" |
| 42 | }).min(PASSWORD_LENGTH_MIN_LIMIT, `Password length should be at least ${PASSWORD_LENGTH_MIN_LIMIT} characters`) |
| 43 | .max(PASSWORD_LENGTH_MAX_LIMIT, `Password cannot exceed more than ${PASSWORD_LENGTH_MAX_LIMIT} characters`), |
| 44 | }).refine((data) => data.password === data.confirm_password, { |
| 45 | message: "Passwords don't match", |
| 46 | path: ["confirm_password"], // path of error |
| 47 | // Password has to have: |
| 48 | // At least 1 uppercase letter |
| 49 | // At least 1 lowercase letter |
| 50 | // At least 1 number |
| 51 | // At least 1 special character |
| 52 | }).superRefine(({ password }, checkPasswordComplexity) => { |
| 53 | // Password has to have: |
| 54 | // At least 1 uppercase letter |
| 55 | const uppercaseRegex = new RegExp("(?=.*[A-Z])") |
| 56 | |
| 57 | // At least 1 lowercase letter |
| 58 | const lowercaseRegex = new RegExp("(?=.*[a-z])") |
| 59 | |
| 60 | // At least 1 number |
| 61 | const numberRegex = new RegExp("(?=.*[0-9])") |
| 62 | |
| 63 | // At least 1 special character |
| 64 | const specialCharacters = "!@#\$%\^&\*+-=~" |
| 65 | const specialCharacterRegex = new RegExp(`(?=.*[${specialCharacters}])`) |
| 66 | |
| 67 | if (!uppercaseRegex.test(password)) { |
| 68 | checkPasswordComplexity.addIssue({ |
| 69 | code: "custom", |
| 70 | message: "Password should contain at least 1 uppercase letter", |
| 71 | path: ["password"] |
| 72 | }) |
| 73 | return |
nothing calls this directly
no outgoing calls
no test coverage detected