Search code examples
fluttergoogle-cloud-firestorefirebase-security

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


I am try to SignUp with google account to firebase and save the data on the firestore then that error shown to me

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

void googleSignInMethod() async {
    final GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
    GoogleSignInAuthentication googleSignInAuthentication =
        await googleUser!.authentication;
    print(googleUser);

    final AuthCredential credential = GoogleAuthProvider.credential(
      idToken: googleSignInAuthentication.idToken,
      accessToken: googleSignInAuthentication.accessToken,
    );

    await _auth.signInWithCredential(credential).then((user) {
      Get.offAll(Country());
      saveUser(user);
    });
  }

and that the code where I save data to the firestore

void saveUser(UserCredential user) async {
    await FireStoreUser().addUserToFireStore(UserModel(
      email: '${user.user!.email}',
      name: name ?? '${user.user!.displayName}',
      pic: '',
      userId: user.user!.uid,
    ));
  }

this one where I set and reseve it form firestore

class FireStoreUser {
  final CollectionReference _userCollectionRef =
      FirebaseFirestore.instance.collection('Users');

  Future<void> addUserToFireStore(UserModel userModel) async {
    return await _userCollectionRef
        .doc(userModel.userId)
        .set(userModel.toJson());
  }
}

Solution

  • I know where is the error in fireStore there is an Rules go there

    rules_version = '1';
    service cloud.firestore {
      match /databases/{database}/documents {
        match /{document=**} {
          allow read, write: if true;
        }
      }
    }
    

    u just change allow read, write: if false; to allow read, write: if true;