fix: resolve infinite loading on user deletion by adding try-finally and deleting from public.users first
All checks were successful
Staging Build / build (push) Successful in 2m35s

This commit is contained in:
DanielS
2026-06-25 01:25:49 +02:00
parent 03d711c2e1
commit 396f135e87
2 changed files with 12 additions and 3 deletions

View File

@@ -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)
}
}
}

View File

@@ -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');