简体   繁体   中英

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

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

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM