fix: verify member removal persistence
This commit is contained in:
parent
bb389d6f78
commit
943f08e92b
1 changed files with 34 additions and 3 deletions
|
|
@ -374,11 +374,42 @@ class CollectionService {
|
|||
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')
|
||||
.delete()
|
||||
.eq('id', targetMembership['id'] as String)
|
||||
.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)
|
||||
.eq('collection_id', collectionId);
|
||||
.maybeSingle();
|
||||
|
||||
if (stillExists != null) {
|
||||
throw Exception('Member removal did not persist. Please try again.');
|
||||
}
|
||||
}
|
||||
|
||||
/// Leave a collection (for non-owners).
|
||||
|
|
|
|||
Loading…
Reference in a new issue