Skip to content

Commit

Permalink
Update password and username validation when registering
Browse files Browse the repository at this point in the history
  • Loading branch information
astijusar committed Nov 29, 2023
1 parent 119f1f9 commit 3c52fdb
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Web UI/src/routes/Register.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ const Register = () => {
email: data.email,
}).unwrap();
navigate("/login");
} catch {
} catch (err) {
console.log(err);
if (!err?.response && err?.status === "FETCH_ERROR") {
setApiError("Unable to reach server. Please try again later!");
} else if (err.response?.status === 400) {
} else if (err.status === 400) {
setError("username", {
type: "manual",
message: "Username is required!",
Expand All @@ -49,6 +50,11 @@ const Register = () => {
type: "manual",
message: "Password is required!",
});
} else if (err.status === 422) {
setError("username", {
type: "manual",
message: "Username is already taken!",
});
} else {
setApiError("Please try again later!");
}
Expand Down Expand Up @@ -128,6 +134,11 @@ const Register = () => {
<input
{...register("password", {
required: true,
pattern: {
value: /^(?=.*\d)(?=.*[/!@#$%^&*])(?=.*[a-z])(?=.*[A-Z]).{6,}$/,
message:
"Password needs to be atleast 6 letters long and have atleast one capital letter, number and special character!",
},
})}
className="input w-full mb-1"
type="password"
Expand Down

0 comments on commit 3c52fdb

Please sign in to comment.