refactor: extract validation schemas to shared module

This commit is contained in:
2026-03-19 23:15:49 +01:00
parent 4ea87c0cf7
commit dd1e3d9053
6 changed files with 77 additions and 61 deletions

View File

@@ -1,10 +1,11 @@
<script setup lang="ts">
import type { AuthFormField, FormSubmitEvent } from '@nuxt/ui'
import type * as v from 'valibot'
import { useForm } from '@inertiajs/vue3'
import * as v from 'valibot'
import { computed } from 'vue'
import { useAuth } from '@/composables/useAuth'
import AuthLayout from '@/layouts/AuthLayout.vue'
import { resetPasswordSchema } from '@/validation/auth'
const props = defineProps<{
email: string
@@ -44,21 +45,7 @@ const fields: AuthFormField[] = [
},
]
const schema = v.pipe(
v.object({
email: v.pipe(v.string('Email is required'), v.nonEmpty('Email is required'), v.email('Please enter a valid email')),
password: v.pipe(v.string('Password is required'), v.nonEmpty('Password is required'), v.minLength(8, 'Password must be at least 8 characters')),
password_confirmation: v.pipe(v.string('Please confirm your password'), v.nonEmpty('Please confirm your password')),
}),
v.forward(
v.partialCheck(
[['password'], ['password_confirmation']],
input => input.password === input.password_confirmation,
'Passwords do not match',
),
['password_confirmation'],
),
)
const schema = resetPasswordSchema
type Schema = v.InferOutput<typeof schema>