feat(frontend): Clean-up schemas, remove dead code, move types

This commit is contained in:
2025-10-03 08:44:15 +02:00
parent 17a3a76054
commit 6c88b4fd96
12 changed files with 136 additions and 351 deletions

View File

@@ -69,7 +69,7 @@
</template>
<script setup lang="ts">
import type { CustomInvitation } from '~/composables/useAuth'
import type { CustomInvitation } from '~/types/auth'
const invitationId = useRoute().params.id as string

View File

@@ -1,11 +1,11 @@
<template>
<UAuthForm
:fields="fields"
:schema="schema"
:schema="signInSchema"
:providers="providers"
title="Welcome back"
icon="i-lucide-lock"
@submit="onSubmit"
@submit="onLoginSubmit"
>
<template #description>
Don't have an account? <ULink to="/signup" class="text-primary-500 font-medium">Sign up</ULink>.
@@ -22,15 +22,15 @@
</template>
<script setup lang="ts">
import * as z from 'zod'
import type { FormSubmitEvent } from '@nuxt/ui'
import { signInSchema, type SignInSchema } from '~/types/schemas'
definePageMeta({ layout: 'auth' })
useSeoMeta({ title: 'Login' })
const toast = useToast()
const { signIn } = useAuth()
const { signIn } = useUserStore()
const fields = [
{
@@ -70,45 +70,11 @@ const providers = [
}
]
const schema = z.object({
email: z.string().email('Invalid email'),
password: z.string().min(8, 'Must be at least 8 characters')
})
type Schema = z.output<typeof schema>
function onSubmit(payload: FormSubmitEvent<Schema>) {
function onLoginSubmit(payload: FormSubmitEvent<SignInSchema>) {
if (!payload.data.email || !payload.data.password) {
alert('Bitte alle Felder ausfüllen')
return
}
signIn.email(
{
email: payload.data.email,
password: payload.data.password
},
{
onRequest: () => {
// TODO: Show loading spinner
console.log('Sending login request')
},
onResponse: () => {
// TODO: Hide loading spinner
console.log('Receiving login response')
},
onSuccess: async (ctx) => {
console.log('Successfully logged in!', ctx)
await navigateTo('/')
},
onError: (ctx) => {
console.log(ctx.error.message)
useToast().add({
title: 'Fehler bei der Anmeldung',
description: ctx.error.message,
color: 'error'
})
}
}
)
signIn(payload)
}
</script>

View File

@@ -1,11 +1,11 @@
<template>
<UAuthForm
:fields="fields"
:schema="schema"
:schema="signUpSchema"
:providers="providers"
title="Create an account"
:submit="{ label: 'Create account' }"
@submit="onSubmit"
@submit="onSignUpSubmit"
>
<template #description>
Already have an account? <ULink to="/login" class="text-primary-500 font-medium">Login</ULink>.
@@ -18,17 +18,15 @@
</template>
<script setup lang="ts">
import * as z from 'zod'
import type { FormSubmitEvent } from '@nuxt/ui'
import { UserRole } from '~/.api-client'
import { signUpSchema, type SignUpSchema } from '~/types/schemas'
definePageMeta({ layout: 'auth' })
useSeoMeta({ title: 'Sign up' })
const toast = useToast()
const { signUp, deleteUser } = useAuth()
const { createUser } = useUser()
const { signUp } = useUserStore()
const fields = [
{
@@ -68,63 +66,7 @@ const providers = [
}
]
const schema = z.object({
name: z.string().min(1, 'Name is required'),
email: z.string().email('Invalid email'),
password: z.string().min(8, 'Must be at least 8 characters')
})
type Schema = z.output<typeof schema>
function onSubmit(payload: FormSubmitEvent<Schema>) {
signUp.email(
{
email: payload.data.email,
password: payload.data.password,
name: payload.data.name
},
{
onRequest: () => {
// TODO: Show loading spinner
console.log('Sending register request')
},
onResponse: () => {
// TODO: Hide loading spinner
console.log('Receiving register response')
},
onSuccess: async (ctx) => {
console.log('Successfully registered!')
// Create user in backend after successful Better Auth registration
try {
console.log('Creating user in backend...', ctx.data)
await createUser({
id: ctx.data.user.id,
name: ctx.data.user.name,
status: 'ACTIVE',
role: UserRole.Employee
})
console.log('User created in backend successfully')
} catch (error) {
console.error('Failed to create user in backend:', error)
toast.add({
title: 'Warning',
description: 'Account created but there was an issue with backend setup. Please contact support.',
color: 'warning'
})
}
await navigateTo('/')
},
onError: async (ctx) => {
console.log(ctx.error.message)
useToast().add({
title: 'Fehler bei der Registrierung',
description: ctx.error.message,
color: 'error'
})
}
}
)
function onSignUpSubmit(payload: FormSubmitEvent<SignUpSchema>) {
signUp(payload)
}
</script>