({ mode })
| 12 | const VITE_SERVER_PORT = import.meta.env.VITE_SERVER_PORT || 'https://bitbox-uxbo.onrender.com'; |
| 13 | |
| 14 | const Signup = ({ mode }) => { |
| 15 | const { userLoggedIn } = useAuth(); |
| 16 | const navigate = useNavigate(); |
| 17 | |
| 18 | console.log(mode); |
| 19 | |
| 20 | const [name, setName] = useState(""); |
| 21 | const [email, setEmail] = useState(""); |
| 22 | const [password, setPassword] = useState(""); |
| 23 | // eslint-disable-next-line |
| 24 | const [cpassword, setCPassword] = useState(""); |
| 25 | // eslint-disable-next-line |
| 26 | const [errors, setErrors] = useState({}); |
| 27 | const [isLoggedIn, setLoggedIn] = useState(false); |
| 28 | const [requirements, setRequirements] = useState({ |
| 29 | length: false, |
| 30 | uppercase: false, |
| 31 | lowercase: false, |
| 32 | number: false, |
| 33 | specialChar: false, |
| 34 | }); |
| 35 | |
| 36 | const handlePasswordChange = (e) => { |
| 37 | const newPassword = e.target.value; |
| 38 | setPassword(newPassword); |
| 39 | |
| 40 | setRequirements({ |
| 41 | length: newPassword.length >= 8, |
| 42 | uppercase: /[A-Z]/.test(newPassword), |
| 43 | lowercase: /[a-z]/.test(newPassword), |
| 44 | number: /\d/.test(newPassword), |
| 45 | specialChar: /[@$!%*?&]/.test(newPassword), |
| 46 | }); |
| 47 | }; |
| 48 | |
| 49 | const handleSubmit = async (e) => { |
| 50 | e.preventDefault(); |
| 51 | |
| 52 | // Check if the password meets the requirements |
| 53 | if (!Object.values(requirements).every(Boolean)) { |
| 54 | setErrors((prevErrors) => ({ |
| 55 | ...prevErrors, |
| 56 | password: "Password does not meet the required criteria.", |
| 57 | })); |
| 58 | return; |
| 59 | } else { |
| 60 | setErrors((prevErrors) => ({ ...prevErrors, password: null })); |
| 61 | } |
| 62 | |
| 63 | // Check if password and confirm password match |
| 64 | if (password !== cpassword) { |
| 65 | setErrors((prevErrors) => ({ |
| 66 | ...prevErrors, |
| 67 | cpassword: "Passwords do not match.", |
| 68 | })); |
| 69 | return; |
| 70 | } else { |
| 71 | setErrors((prevErrors) => ({ ...prevErrors, cpassword: null })); |
nothing calls this directly
no test coverage detected