diff --git a/src/SignupPage.tsx b/src/SignupPage.tsx index b538631..4961352 100644 --- a/src/SignupPage.tsx +++ b/src/SignupPage.tsx @@ -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") { diff --git a/src/helpers.tsx b/src/helpers.tsx index 373b25b..d77d789 100644 --- a/src/helpers.tsx +++ b/src/helpers.tsx @@ -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; +}