feat: confirm admin creation password
This commit is contained in:
@@ -6,12 +6,18 @@ const optionalPassword = z.string().refine((value) => value.length === 0 || valu
|
|||||||
});
|
});
|
||||||
const roleSchema = z.enum(['admin', 'user'], 'Select a role.');
|
const roleSchema = z.enum(['admin', 'user'], 'Select a role.');
|
||||||
|
|
||||||
export const createAdminSchema = z.object({
|
export const createAdminSchema = z
|
||||||
|
.object({
|
||||||
name: z.string().trim().min(1, 'Enter a name.'),
|
name: z.string().trim().min(1, 'Enter a name.'),
|
||||||
email: z.email('Enter a valid email address.').transform((value) => value.toLowerCase()),
|
email: z.email('Enter a valid email address.').transform((value) => value.toLowerCase()),
|
||||||
password: optionalPassword,
|
password: optionalPassword,
|
||||||
|
confirmPassword: optionalPassword,
|
||||||
role: roleSchema.default('admin')
|
role: roleSchema.default('admin')
|
||||||
});
|
})
|
||||||
|
.refine((data) => data.password === data.confirmPassword, {
|
||||||
|
message: 'Confirm password must match password.',
|
||||||
|
path: ['confirmPassword']
|
||||||
|
});
|
||||||
|
|
||||||
export const editAdminSchema = z.object({
|
export const editAdminSchema = z.object({
|
||||||
id: z.string().min(1, 'Admin id is required.'),
|
id: z.string().min(1, 'Admin id is required.'),
|
||||||
|
|||||||
@@ -76,6 +76,23 @@
|
|||||||
<Field.Error><FieldErrors /></Field.Error>
|
<Field.Error><FieldErrors /></Field.Error>
|
||||||
</Field.Field>
|
</Field.Field>
|
||||||
</FormField>
|
</FormField>
|
||||||
|
<FormField form={createForm} name="confirmPassword">
|
||||||
|
<Field.Field>
|
||||||
|
<Control id="create-confirm-password">
|
||||||
|
{#snippet children({ props })}
|
||||||
|
<Field.Label>Confirm password</Field.Label>
|
||||||
|
<Input
|
||||||
|
{...props}
|
||||||
|
type="password"
|
||||||
|
autocomplete="new-password"
|
||||||
|
placeholder="Repeat password"
|
||||||
|
bind:value={$createData.confirmPassword}
|
||||||
|
/>
|
||||||
|
{/snippet}
|
||||||
|
</Control>
|
||||||
|
<Field.Error><FieldErrors /></Field.Error>
|
||||||
|
</Field.Field>
|
||||||
|
</FormField>
|
||||||
<FormField form={createForm} name="role">
|
<FormField form={createForm} name="role">
|
||||||
<Field.Field>
|
<Field.Field>
|
||||||
<Control id="create-role">
|
<Control id="create-role">
|
||||||
|
|||||||
Reference in New Issue
Block a user