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
All checks were successful
Staging Build / build (push) Successful in 2m35s
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user