Skip to content

Commit b536b6a

Browse files
committed
fix: add password strength feedback to create user form
1 parent e99bcab commit b536b6a

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

apps/web/src/features/admin/pages/CreateUserPage.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable perfectionist/sort-objects */
22

3+
import { estimatePasswordStrength } from '@douglasneuroinformatics/libpasswd';
34
import { Form, Heading } from '@douglasneuroinformatics/libui/components';
45
import { useTranslation } from '@douglasneuroinformatics/libui/hooks';
56
import { $BasePermissionLevel, $CreateUserData, type CreateUserData } from '@opendatacapture/schemas/user';
@@ -44,6 +45,9 @@ export const CreateUserPage = () => {
4445
variant: 'input'
4546
},
4647
password: {
48+
calculateStrength: (password) => {
49+
return estimatePasswordStrength(password).score;
50+
},
4751
kind: 'string',
4852
label: t('common.password'),
4953
variant: 'password'
@@ -125,6 +129,15 @@ export const CreateUserPage = () => {
125129
confirmPassword: z.string().min(1)
126130
})
127131
.superRefine((arg, ctx) => {
132+
if (!estimatePasswordStrength(arg.password).success) {
133+
ctx.addIssue({
134+
code: z.ZodIssueCode.custom,
135+
fatal: true,
136+
message: t('common.insufficientPasswordStrength'),
137+
path: ['password']
138+
});
139+
return z.NEVER;
140+
}
128141
if (arg.confirmPassword !== arg.password) {
129142
ctx.addIssue({
130143
code: z.ZodIssueCode.custom,

0 commit comments

Comments
 (0)