TorrenceB
TorrenceB

Reputation: 21

Firestore security rules Flutter app denied permissions

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.

Upvotes: 1

Views: 1060

Answers (1)

TorrenceB
TorrenceB

Reputation: 21

@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.

Upvotes: 1

Related Questions