diff --git a/shop/components/admin/user-list.tsx b/shop/components/admin/user-list.tsx index 6476a89..f282ec9 100644 --- a/shop/components/admin/user-list.tsx +++ b/shop/components/admin/user-list.tsx @@ -59,9 +59,15 @@ export function UserList({ initialUsers, companies }: UserListProps) { const handleDelete = async (id: string) => { if (confirm('Möchten Sie diesen Benutzer wirklich löschen?')) { setLoadingId(id) - await deleteUser(id) - setLoadingId(null) - router.refresh() + try { + await deleteUser(id) + router.refresh() + } catch (e: any) { + console.error('Fehler beim Löschen des Benutzers:', e) + alert('Fehler beim Löschen: ' + (e.message || JSON.stringify(e))) + } finally { + setLoadingId(null) + } } } diff --git a/shop/lib/actions/users.ts b/shop/lib/actions/users.ts index 9b16a54..132eb5a 100644 --- a/shop/lib/actions/users.ts +++ b/shop/lib/actions/users.ts @@ -91,6 +91,9 @@ export async function createUser(data: { email: string; role?: 'admin' | 'partne export async function deleteUser(id: string) { const admin = createAdminClient(); + // Delete from public.users first to satisfy foreign key constraints + await admin.from('users').delete().eq('id', id); + const { error } = await admin.auth.admin.deleteUser(id); if (error) throw error; revalidatePath('/admin/users');