feat(frontend): Move better auth functions into separate file
This commit is contained in:
49
legalconsenthub/composables/useBetterAuth.ts
Normal file
49
legalconsenthub/composables/useBetterAuth.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
const activeOrganization = ref<ActiveOrganization | null>(null)
|
||||
const selectedOrgId = ref<string | undefined>(undefined)
|
||||
|
||||
export function useBetterAuth() {
|
||||
const toast = useToast()
|
||||
|
||||
async function createOrganization(name: string, slug: string, logo?: string) {
|
||||
await organization.create(
|
||||
{ name, slug, logo },
|
||||
{
|
||||
onSuccess: () => {
|
||||
toast.add({ title: 'Organisation erfolgreich erstellt', color: 'success' })
|
||||
return Promise.resolve()
|
||||
},
|
||||
onError: (ctx) => {
|
||||
toast.add({
|
||||
title: 'Fehler bei der Erstellung der Organisation',
|
||||
description: ctx.error.message,
|
||||
color: 'error'
|
||||
})
|
||||
return Promise.reject()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async function deleteOrganization() {
|
||||
await authClient.organization.delete(
|
||||
{ organizationId: activeOrganization.value?.id ?? '' },
|
||||
{
|
||||
onSuccess: () => {
|
||||
toast.add({ title: 'Organization deleted', color: 'success' })
|
||||
activeOrganization.value = null
|
||||
selectedOrgId.value = undefined
|
||||
},
|
||||
onError: (ctx) => {
|
||||
toast.add({ title: 'Error deleting organization', description: ctx.error.message, color: 'error' })
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
activeOrganization,
|
||||
selectedOrgId,
|
||||
createOrganization,
|
||||
deleteOrganization
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user