Password rules: move to a helper function.

master
Tom Hacohen 4 years ago
parent b04a7bed5e
commit 17fb106aa8

@ -20,7 +20,7 @@ import { CircularProgress } from "@material-ui/core";
import { Redirect } from "react-router";
import { useCredentials } from "./credentials";
import { useDispatch } from "react-redux";
import { startTask } from "./helpers";
import { startTask, PASSWORD_MIN_LENGTH, enforcePasswordRules } from "./helpers";
import { login } from "./store/actions";
import { Link } from "react-router-dom";
@ -34,8 +34,6 @@ interface FormErrors {
errorGeneral?: string;
}
const PASSWORD_MIN_LENGTH = 8;
export default function SignupPage() {
const credentials = useCredentials();
const dispatch = useDispatch();
@ -67,8 +65,11 @@ export default function SignupPage() {
}
if (!password) {
errors.errorPassword = fieldRequired;
} else if (password.length < PASSWORD_MIN_LENGTH) {
errors.errorPassword = `Passwourds should be at least ${PASSWORD_MIN_LENGTH} digits long.`;
} else {
const passwordRulesError = enforcePasswordRules(password);
if (passwordRulesError) {
errors.errorPassword = passwordRulesError;
}
}
if (process.env.NODE_ENV !== "development") {

@ -201,3 +201,13 @@ export function parseDate(prop: ICAL.Property) {
return {};
}
export const PASSWORD_MIN_LENGTH = 8;
export function enforcePasswordRules(password: string): string | undefined {
if (password.length < PASSWORD_MIN_LENGTH) {
return `Passwourds should be at least ${PASSWORD_MIN_LENGTH} digits long.`;
}
return undefined;
}

Loading…
Cancel
Save