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,9 +1,10 @@
<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 AuthLayout from '@/layouts/AuthLayout.vue'
import { completeProfileSchema } from '@/validation/auth'
const props = defineProps<{
socialiteUser: {
@@ -46,16 +47,7 @@ const fields: AuthFormField[] = [
},
]
const schema = v.object({
username: v.pipe(
v.string('Username is required'),
v.nonEmpty('Username is required'),
v.minLength(3, 'Username must be at least 3 characters'),
v.regex(/^[\w-]+$/, 'Username can only contain letters, numbers, dashes and underscores'),
),
first_name: v.pipe(v.string('First name is required'), v.nonEmpty('First name is required')),
last_name: v.pipe(v.string('Last name is required'), v.nonEmpty('Last name is required')),
})
const schema = completeProfileSchema
type Schema = v.InferOutput<typeof schema>