Home > Back-end >  cloud_firestore/permission-denied The caller does not have permission to execute the specified opera
cloud_firestore/permission-denied The caller does not have permission to execute the specified opera

Time:08-20

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());
  }
}

CodePudding user response:

Can you share your Firestore Rules with us;

https://console.firebase.google.com/project/[YourAppName]/firestore/rules

The following rule will allow authenticated users write and read Firestore data.

rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
 match /{document=**} {
  allow read, write: if request.auth != null;
  }
 }
}

CodePudding user response:

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;

  • Related