feat(frontend): Move better auth functions into separate file

This commit is contained in:
2025-04-06 18:37:18 +02:00
parent eed4b673c0
commit 068dc1305f
3 changed files with 61 additions and 43 deletions

View File

@@ -33,11 +33,12 @@
</template>
<script setup lang="ts">
import type { FormSubmitEvent } from '@nuxt/ui'
import * as z from 'zod'
import { useBetterAuth } from '~/composables/useBetterAuth'
const emit = defineEmits(['formSubmitted'])
const { createOrganization } = useBetterAuth()
const open = ref(false)
const loading = ref(false)
const isSlugEdited = ref(false)
@@ -86,32 +87,14 @@ function handleLogoChange(event: Event) {
reader.readAsDataURL(file)
}
async function onSubmit(event: FormSubmitEvent<Schema>) {
console.log('onSubmit', state)
async function onSubmit() {
loading.value = true
await organization.create(
{
name: event.data.name,
slug: event.data.slug,
logo: event.data.logo
},
{
onSuccess: () => {
useToast().add({ title: 'Organisation erfolgreich erstellt', color: 'success' })
emit('formSubmitted', { name: state.name, slug: state.slug })
open.value = false
},
onError: (ctx) => {
useToast().add({
title: 'Fehler bei der Erstellung der Organisation',
description: ctx.error.message,
color: 'error'
})
},
onResponse: () => {
loading.value = false
}
}
)
if (!state.name || !state.slug) return
await createOrganization(state.name, state.slug, state.logo)
emit('formSubmitted', { name: state.name, slug: state.slug })
loading.value = false
open.value = false
}
</script>