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

@@ -1,13 +1,15 @@
import type {
ActiveOrganization,
Organization,
Invitation,
ListMembersOptions,
ListMembersResponse,
ListMembersQuery
} from '~/composables/useAuth'
import { useOrganizationApi } from '~/composables/organization/useOrganizationApi'
import type { LegalRole } from '~/server/utils/permissions'
import type {
ActiveOrganization,
CustomInvitation,
Invitation,
ListMembersOptions,
ListMembersQuery,
ListMembersResponse,
Member,
Organization
} from '~/types/auth'
export const useOrganizationStore = defineStore('Organization', () => {
const activeOrganization = ref<ActiveOrganization | null>(null)

View File

@@ -1,39 +1,82 @@
import type { FormSubmitEvent } from '@nuxt/ui'
import { UserRole } from '~/.api-client'
import type { SignInSchema, SignUpSchema } from '~/types/schemas'
export const useUserStore = defineStore('User', () => {
const { createUser } = useUser()
const name = ref('')
const toast = useToast()
const { client } = useAuth()
async function signUp(payload: FormSubmitEvent<Schema>) {
await authClient.signUp.email(
async function signUp(payload: FormSubmitEvent<SignUpSchema>) {
await client.signUp.email(
{
email: payload.data.email,
password: payload.data.password,
name: payload.data.name
},
{
onRequest: (ctx) => {
// TODO: Show loading spinner
onRequest: () => {
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: (ctx) => {
onError: async (ctx) => {
console.log(ctx.error.message)
useToast().add({
title: 'Fehler bei der Registrierung',
description: ctx.error.message,
color: 'success'
color: 'error'
})
}
}
)
}
return { name, signUp }
async function signIn(payload: FormSubmitEvent<SignInSchema>) {
await client.signIn.email(
{
email: payload.data.email,
password: payload.data.password
},
{
onRequest: () => {
console.log('Sending login request')
},
onSuccess: () => {
console.log('Successfully logged in!')
},
onError: (ctx) => {
console.log(ctx.error.message)
}
}
)
}
return { name, signUp, signIn }
})