fix(admin): delete auth user on profile update failure

This commit is contained in:
2026-07-18 18:00:00 +08:00
parent 33d4dd4b27
commit d5803daa67
+3 -1
View File
@@ -67,11 +67,13 @@ export async function POST(request: NextRequest) {
site_id: body.site_id ?? null, site_id: body.site_id ?? null,
}) })
.eq('id', newUserId) .eq('id', newUserId)
if (profileError) if (profileError) {
await admin.auth.admin.deleteUser(newUserId)
return NextResponse.json( return NextResponse.json(
{ error: 'User created but profile update failed' }, { error: 'User created but profile update failed' },
{ status: 500 }, { status: 500 },
) )
}
await supabase.rpc('write_audit_log', { await supabase.rpc('write_audit_log', {
p_table_name: 'users', p_table_name: 'users',