Firestore security rules Flutter app denied permissions

535

@DougStevenson thank you man! Turns out I was attempting to pull data from the wrong project within my Firebase console. Strange scenario but your comment encouraged me to think outside of the box.

The cause was placing the wrong GoogleService-Info.plist file from a different project inside of my Runner file.

Share:
535
TorrenceB
Author by

TorrenceB

Updated on December 25, 2022

Comments

  • TorrenceB
    TorrenceB over 1 year

    I'm currently attempting to connect my Firebase backend to my Flutter app. Upon creating a simple get() request to Firestore I keep coming across the same error every single time:

    [cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.

    The security rules that I've attempted:

    service cloud.firestore {
      match /databases/{database}/documents {
        match /{document=**} {
          allow read, write: if request.time < timestamp.date(2020, 11, 30);
        }
      }
    }
    
    allow read, write;
    
    allow read, write: if true;
    
    allow read, write: if request.auth.uid != null;
    
    allow read, write: if request.auth != null;
    
    allow read, write: if auth != null ;
    

    I've literally tried everything under the sun with no success at reading or writing to my Database which leads me to believe that the fault lies somewhere in my code. I've checked to make sure that Firebase is correctly initialized, Firebase Core and Firebase Firestore have both been correctly initialized as well.

    Is this a Firebase issue or is there a specific way that calls to Firestore need to be performed?

    Get request:

      fetchChatMessages() async {
        var messageSnapShots =
            await FirebaseFirestore.instance.collection('topicofday').get();
    
        print('Messages: $messageSnapShots');
      }
    }
    

    Initialize Firebase:

    class MyApp extends StatelessWidget {
      final Future<FirebaseApp> _initialization = Firebase.initializeApp();
      @override
      FutureBuilder build(BuildContext context) {
        return FutureBuilder(
          future: _initialization,
          builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
            if (snapshot.connectionState == ConnectionState.done) {
              return buildMaterialApp(context);
            }
            return Center(
              child: Container(
                child: CircularProgressIndicator(
                  backgroundColor: Theme.of(context).primaryColor,
                ),
              ),
            );
          },
        );
      }
    

    Additional info:

    Not sure if this would affect the request at all but I'm using Provider for State Management.

    • Doug Stevenson
      Doug Stevenson over 3 years
      What exactly are you doing to update your rules? Edit the question to walk through the steps you take.
    • TorrenceB
      TorrenceB over 3 years
      Are you referring to updating the rules in Firestore?? As in making the appropriate changes to the rules then publishing?
    • Doug Stevenson
      Doug Stevenson over 3 years
      Yes, it's possible that you're either not actually publishing new rules at all, or you might be publishing rules in a different project.
    • Harif Velarde
      Harif Velarde over 3 years
      why you are setting this condition? allow read, write: if request.time < timestamp.date(2020, 11, 30); in other posts they use another settings for access to firestore stackoverflow.com/questions/52422047/…
    • Harif Velarde
      Harif Velarde over 3 years
      Can you share your solution as an answer on this post? This information could help other users with a similar scenario.
  • Aditi
    Aditi about 2 years
    B I am also facing same kind of issue and even checked the project as well, but getting same error