Sign out error Cloud Firestore. The caller does not have permission to execute the specified operation

798

That happens because somewhere in your app you’re probably still keeping stream subscriptions to some Firestore queries that aren’t accessible after you sign out because you’re correctly preventing it with the rules.

Check your project code and look for any eventual subscriptions that aren’t being canceled before the user signs out.

Share:
798
James 666
Author by

James 666

Flutter developer, 2 years and counting...

Updated on December 25, 2022

Comments

  • James 666
    James 666 over 1 year

    I have a flutter app where I have signed in users successfully and no errors are thrown up. But, when I attempt FirebaseAuth.instance.signOut() in one of my buttons, it signs the user out but throws up this error. I have attached my cloud firestore rules below.

    rules_version = '2';
    service cloud.firestore {
      match /databases/{database}/documents {
      
        match /merchants/{document=**} {
          allow read;
        }
        match /all_merchants/{document=**} {
          allow read;
        }
        match /Types/{document=**} {
          allow read;
        }
        match /Promotions/{document=**} {
          allow read;
        }
        match /search_types/{document=**} {
          allow read;
        }
    
        
        match /users/{userId} {
          allow read, update, delete: if request.auth.uid == userId;
          allow create: if request.auth.uid != null;
          
          match /{document=**}{
            allow read, update, create, delete: if request.auth.uid == userId;
          }
        }
        
         match /users/{email} {
          allow read, update, delete: if request.auth.token.email == email;
          allow create: if request.auth.token.email != null;
          
          match /{document=**}{
            allow read, update, create, delete: if request.auth.token.email == email;
          }
        }
        
        
      }
    }
    

    (edit): My Flutter code for the button is as below:

    import 'package:firebase_auth/firebase_auth.dart';
    import 'package:flutter/material.dart';
    
    
    class SignOut extends StatelessWidget {
    
      FirebaseAuth auth = FirebaseAuth.instance;
    
    
      @override
      Widget build(BuildContext context) {
    
    GestureDetector(
          onTap: (){
              setState(() {
                    auth.signOut();
                   });
                },
          child: ListTile(
            dense: true,
            leading: Icon(Icons.exit_to_app, color: Colors.red[600], size: 25,),
            title: Text('Sign Out',
                        style: TextStyle(fontFamily: 'Lato', fontSize: 18, fontWeight: FontWeight.w500),),
            trailing: Icon(Icons.arrow_forward_ios, color: Colors.black, size: 19,),
          ),
        );
    }
    }