added min password length rule
This commit is contained in:
parent
ae71ce2020
commit
67989b7c05
|
@ -37,40 +37,44 @@ export default function ChangePassword({
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
if (newPassword == "" || newPassword2 == "") {
|
if (newPassword == "" || newPassword2 == "") {
|
||||||
toast.error("Please fill all the fields.");
|
toast.error("Please fill all the fields.");
|
||||||
} else if (newPassword === newPassword2) {
|
|
||||||
setSubmitLoader(true);
|
|
||||||
|
|
||||||
const load = toast.loading("Applying...");
|
|
||||||
|
|
||||||
const response = await updateAccount({
|
|
||||||
...user,
|
|
||||||
});
|
|
||||||
|
|
||||||
toast.dismiss(load);
|
|
||||||
|
|
||||||
if (response.ok) {
|
|
||||||
toast.success("Settings Applied!");
|
|
||||||
|
|
||||||
if (user.email !== account.email) {
|
|
||||||
update({
|
|
||||||
id: data?.user.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
signOut();
|
|
||||||
} else if (
|
|
||||||
user.username !== account.username ||
|
|
||||||
user.name !== account.name
|
|
||||||
)
|
|
||||||
update({
|
|
||||||
id: data?.user.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
setUser({ ...user, newPassword: undefined });
|
|
||||||
togglePasswordFormModal();
|
|
||||||
} else toast.error(response.data as string);
|
|
||||||
} else {
|
|
||||||
toast.error("Passwords do not match.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newPassword !== newPassword2)
|
||||||
|
return toast.error("Passwords do not match.");
|
||||||
|
else if (newPassword.length < 8)
|
||||||
|
return toast.error("Passwords must be at least 8 characters.");
|
||||||
|
|
||||||
|
setSubmitLoader(true);
|
||||||
|
|
||||||
|
const load = toast.loading("Applying...");
|
||||||
|
|
||||||
|
const response = await updateAccount({
|
||||||
|
...user,
|
||||||
|
});
|
||||||
|
|
||||||
|
toast.dismiss(load);
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
toast.success("Settings Applied!");
|
||||||
|
|
||||||
|
if (user.email !== account.email) {
|
||||||
|
update({
|
||||||
|
id: data?.user.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
signOut();
|
||||||
|
} else if (
|
||||||
|
user.username !== account.username ||
|
||||||
|
user.name !== account.name
|
||||||
|
)
|
||||||
|
update({
|
||||||
|
id: data?.user.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
setUser({ ...user, newPassword: undefined });
|
||||||
|
togglePasswordFormModal();
|
||||||
|
} else toast.error(response.data as string);
|
||||||
|
|
||||||
setSubmitLoader(false);
|
setSubmitLoader(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -53,35 +53,35 @@ export default function Register() {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (checkHasEmptyFields()) {
|
if (checkHasEmptyFields()) {
|
||||||
if (form.password === form.passwordConfirmation) {
|
if (form.password !== form.passwordConfirmation)
|
||||||
const { passwordConfirmation, ...request } = form;
|
return toast.error("Passwords do not match.");
|
||||||
|
else if (form.password.length < 8)
|
||||||
|
return toast.error("Passwords must be at least 8 characters.");
|
||||||
|
const { passwordConfirmation, ...request } = form;
|
||||||
|
|
||||||
setSubmitLoader(true);
|
setSubmitLoader(true);
|
||||||
|
|
||||||
const load = toast.loading("Creating Account...");
|
const load = toast.loading("Creating Account...");
|
||||||
|
|
||||||
const response = await fetch("/api/auth/register", {
|
const response = await fetch("/api/auth/register", {
|
||||||
body: JSON.stringify(request),
|
body: JSON.stringify(request),
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
method: "POST",
|
method: "POST",
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
toast.dismiss(load);
|
toast.dismiss(load);
|
||||||
setSubmitLoader(false);
|
setSubmitLoader(false);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
if (form.email) await sendConfirmation();
|
if (form.email) await sendConfirmation();
|
||||||
|
|
||||||
toast.success("User Created!");
|
toast.success("User Created!");
|
||||||
} else {
|
|
||||||
toast.error(data.response);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
toast.error("Passwords do not match.");
|
toast.error(data.response);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
toast.error("Please fill out all the fields.");
|
toast.error("Please fill out all the fields.");
|
||||||
|
|
Ŝarĝante…
Reference in New Issue