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

@ -201,3 +201,13 @@ export function parseDate(prop: ICAL.Property) {
return {}; 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