fix: verify member removal persistence

This commit is contained in:
Lukas Müllner 2026-03-05 11:05:46 +01:00
parent bb389d6f78
commit 943f08e92b

View file

@ -374,11 +374,42 @@ class CollectionService {
throw Exception('Collection owner cannot be removed.'); throw Exception('Collection owner cannot be removed.');
} }
await supabase final targetMembership = await supabase
.from('collection_members')
.select('id, role')
.eq('collection_id', collectionId)
.eq('user_id', memberUserId)
.maybeSingle();
if (targetMembership == null) {
throw Exception('Member not found in this collection.');
}
if (targetMembership['role'] == 'owner') {
throw Exception('Collection owner cannot be removed.');
}
final deleted = await supabase
.from('collection_members') .from('collection_members')
.delete() .delete()
.eq('user_id', memberUserId) .eq('id', targetMembership['id'] as String)
.eq('collection_id', collectionId); .select('id');
if (deleted.isEmpty) {
throw Exception(
'Member could not be removed (blocked by database policy).',
);
}
final stillExists = await supabase
.from('collection_members')
.select('id')
.eq('collection_id', collectionId)
.eq('user_id', memberUserId)
.maybeSingle();
if (stillExists != null) {
throw Exception('Member removal did not persist. Please try again.');
}
} }
/// Leave a collection (for non-owners). /// Leave a collection (for non-owners).