feat(frontend): Clean-up schemas, remove dead code, move types
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user