RivaanRanawat / instagram-flutter-clone

Responsive Instagram Clone developed with Flutter & Firebase
https://youtu.be/BBccK1zTgxw
858 stars 474 forks source link

Can any user delete the post from the feed instead of just the post Owner ? Is it just happening with me ? #31

Closed Kapil619 closed 7 months ago

Kapil619 commented 7 months ago

ListView( padding: const EdgeInsets.symmetric(vertical: 16), shrinkWrap: true, children: ['Delete'] .map( (e) => InkWell( onTap: () async { FirestoreMethods().deletePost( widget.snap['postId'], ); Navigator.of(context).pop(); }, child: Container( padding: const EdgeInsets.symmetric( vertical: 12, horizontal: 16, ), child: Text(e), ), ), )

As we don't check for, If logged in user is same as the user who posted, It causes this bug.

Kapil619 commented 7 months ago

I fixed the issue by changing this in the code =>


onTap: () async {
        user.uid == widget.snap['uid']
         ? await FirestoreMethods().deletePost( widget.snap['postId'],  )
           : showSnackBar(
              "Unable TO delete Post", context);
        Navigator.of(context).pop(); },