diff --git a/legalconsenthub/components/CreateOrganizationModal.vue b/legalconsenthub/components/CreateOrganizationModal.vue
index 79593b7..5750ac6 100644
--- a/legalconsenthub/components/CreateOrganizationModal.vue
+++ b/legalconsenthub/components/CreateOrganizationModal.vue
@@ -36,7 +36,9 @@
import * as z from 'zod'
import { useBetterAuth } from '~/composables/useBetterAuth'
-const emit = defineEmits(['formSubmitted'])
+const emit = defineEmits<{
+ (e: 'organizationCreated', id: string | undefined): void
+}>()
const { createOrganization } = useBetterAuth()
const open = ref(false)
@@ -92,8 +94,8 @@ async function onSubmit() {
if (!state.name || !state.slug) return
- await createOrganization(state.name, state.slug, state.logo)
- emit('formSubmitted', { name: state.name, slug: state.slug })
+ const organization = await createOrganization(state.name, state.slug, state.logo)
+ emit('organizationCreated', organization.data?.id)
loading.value = false
open.value = false
}
diff --git a/legalconsenthub/pages/administration.vue b/legalconsenthub/pages/administration.vue
index caf45ea..b2cd12e 100644
--- a/legalconsenthub/pages/administration.vue
+++ b/legalconsenthub/pages/administration.vue
@@ -29,7 +29,7 @@
placeholder="Select organization"
class="w-64"
/>
-
+
@@ -147,18 +147,38 @@ const { copy, copied } = useClipboard()
const toast = useToast()
const { organization } = useAuth()
-const organizations = (await organization.list()).data || []
const { deleteOrganization: betterAuthDeleteOrganization, activeOrganization, selectedOrgId } = useBetterAuth()
-const availableOrganizations = computed(() => organizations.map((org) => ({ label: org.name, value: org.id })))
+
+const organizations = ref<
+ Array<{ id: string; name: string; slug: string; createdAt: Date; logo?: string | null; metadata?: unknown }>
+>([])
+const availableOrganizations = computed(() => organizations.value.map((org) => ({ label: org.name, value: org.id })))
+
+const { user } = await useAuth()
+
+const isRevoking = ref([])
watch(selectedOrgId, async (newId) => {
const { data } = await organization.setActive({ organizationId: newId || null })
activeOrganization.value = data
})
-const { user } = await useAuth()
+await loadOrganizations()
-const isRevoking = ref([])
+async function loadOrganizations() {
+ try {
+ const response = await organization.list()
+ organizations.value = response.data || []
+ } catch (error) {
+ const errorMessage = error instanceof Error ? error.message : 'Failed to load organizations'
+ toast.add({ title: 'Error', description: errorMessage, color: 'error' })
+ }
+}
+
+async function setOrganization(id: string | undefined) {
+ await loadOrganizations()
+ selectedOrgId.value = id
+}
function isAdminOrOwner(member: { role: string }) {
return member.role === 'owner' || member.role === 'admin'