Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

added min password length rule

Daniel67989b7c0540
diff --git a/components/Modal/User/ChangePassword.tsx b/components/Modal/User/ChangePassword.tsx
index a0074085..4c95d8e8 100644
--- a/components/Modal/User/ChangePassword.tsx
+++ b/components/Modal/User/ChangePassword.tsx
@@ -37,40 +37,44 @@ export default function ChangePassword({
const submit = async () => {
if (newPassword == "" || newPassword2 == "") {
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);
};
diff --git a/pages/register.tsx b/pages/register.tsx
index 4ae3fe2b..c047e17c 100644
--- a/pages/register.tsx
+++ b/pages/register.tsx
@@ -53,35 +53,35 @@ export default function Register() {
};
if (checkHasEmptyFields()) {
- if (form.password === form.passwordConfirmation) {
- const { passwordConfirmation, ...request } = form;
-
- setSubmitLoader(true);
-
- const load = toast.loading("Creating Account...");
-
- const response = await fetch("/api/auth/register", {
- body: JSON.stringify(request),
- headers: {
- "Content-Type": "application/json",
- },
- method: "POST",
- });
+ if (form.password !== form.passwordConfirmation)
+ 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);
+
+ const load = toast.loading("Creating Account...");
+
+ const response = await fetch("/api/auth/register", {
+ body: JSON.stringify(request),
+ headers: {
+ "Content-Type": "application/json",
+ },
+ method: "POST",
+ });
- const data = await response.json();
+ const data = await response.json();
- toast.dismiss(load);
- setSubmitLoader(false);
+ toast.dismiss(load);
+ setSubmitLoader(false);
- if (response.ok) {
- if (form.email) await sendConfirmation();
+ if (response.ok) {
+ if (form.email) await sendConfirmation();
- toast.success("User Created!");
- } else {
- toast.error(data.response);
- }
+ toast.success("User Created!");
} else {
- toast.error("Passwords do not match.");
+ toast.error(data.response);
}
} else {
toast.error("Please fill out all the fields.");