diff --git a/packages/app/src/AuthPage.tsx b/packages/app/src/AuthPage.tsx index 6e5aec8c9..ca625a494 100644 --- a/packages/app/src/AuthPage.tsx +++ b/packages/app/src/AuthPage.tsx @@ -7,6 +7,7 @@ import { useEffect } from 'react'; import Link from 'next/link'; import cx from 'classnames'; +import { PasswordCheck, CheckOrX } from './PasswordCheck'; import LandingHeader from './LandingHeader'; import * as config from './config'; import api from './api'; @@ -24,6 +25,7 @@ export default function AuthPage({ action }: { action: 'register' | 'login' }) { handleSubmit, formState: { errors, isSubmitting }, setError, + watch, } = useForm({ reValidateMode: 'onSubmit', }); @@ -45,6 +47,13 @@ export default function AuthPage({ action }: { action: 'register' | 'login' }) { } }, [installation, isRegister, router]); + const currentPassword = watch('password', ''); + const confirmPassword = watch('confirmPassword', ''); + + const confirmPass = () => { + return currentPassword === confirmPassword; + }; + const onSubmit: SubmitHandler = data => registerPassword.mutate( { @@ -153,15 +162,21 @@ export default function AuthPage({ action }: { action: 'register' | 'login' }) { htmlFor="confirmPassword" className="text-start text-muted fs-7.5 mb-1" > - Confirm Password + + Confirm Password + + )} {isRegister && Object.keys(errors).length > 0 && ( diff --git a/packages/app/src/PasswordCheck.tsx b/packages/app/src/PasswordCheck.tsx new file mode 100644 index 000000000..f8a6722a3 --- /dev/null +++ b/packages/app/src/PasswordCheck.tsx @@ -0,0 +1,70 @@ +import { useMemo } from 'react'; + +const checkLength = (password: string) => password.length >= 12; +const checkOneUpper = (password: string) => /[A-Z]+/.test(password); +const checkOneLower = (password: string) => /[a-z]+/.test(password); +const checkOneNumber = (password: string) => /\d+/.test(password); +const checkOneSpecial = (password: string) => /\W+/.test(password); + +export const PasswordCheck = (opts: { password: string }) => { + const password = opts.password; + return ( +
+
+ + minimum 12 characters + +
+
+ + at least 1 uppercase + +
+
+ + at least 1 lowercase + +
+
+ + at least 1 number + +
+
+ + at least 1 special character + +
+
+ ); +}; + +export const CheckOrX = ({ + handler, + password, + children, +}: { + handler: (password: string) => boolean; + password: string | { password: string | null }; + children: React.ReactNode; +}) => { + let actualPassword = ''; + if (typeof password === 'string') { + actualPassword = password; + } else { + actualPassword = password.password ?? ''; + } + const isValid = useMemo( + () => handler(actualPassword), + [handler, actualPassword], + ); + return ( + + {isValid ? : } {children} + + ); +}; + +const Check = () => ; + +const XShape = () => ;