1

I have ploblems with English. I apologize in advance. Problems with firestore and auth

Error: [firestore/permission-denied] The caller does not have permission to execute the specified operation. NativeFirebaseError: [firestore/permission-denied] The caller does not have permission to execute the specified operation.

My rules in FireStore:

rules_version = '2';
service cloud.firestore {


match/databases/{database}/documents {
    match /Users/{document=**} {
      allow read, get: if true;
      allow create, update: if request.auth.uid == resource.id;
  }
}

I using npm package:

  • @react-native-firebase/app
  • @react-native-firebase/app-check
  • @react-native-firebase/auth
  • @react-native-firebase/firestore

My code:

import auth from '@react-native-firebase/auth';
import firestore from '@react-native-firebase/firestore';
    
async function onAuthChanged(onChange) {
  auth().onAuthStateChanged(onChange);
}

async function authenticateUser(status) {


  if (status) {

    const uid = status.uid;        
    let user = await firestore().collection('Users').doc(uid).get(); // Error
    
    

    return ({
      user: {...user.data(), uid} ?? {login: undefined, birthday: undefined, uid}
    });
  } else {

    return { user: null };
  }
}

onAuthChanged(async (status) => {
  const { user } = await authenticateUser(status);
});

P.S. In fireStore my rules work: enter image description here

P.S.S. This is my first time working with Firebase and everything worked for the first two weeks with standard rules, but today it gives an error. and I do not know why. Although they offer me to put true on all the rules. This does not help in any way for 6-7 hours I have been trying to understand, so I have already turned here.

HardKoT
  • 21
  • 2
  • Hello, did you check this solution : https://stackoverflow.com/questions/37403747/firebase-permission-denied – Gökhan Geyik Jan 25 '22 at 09:27
  • @GökhanGeyik, Thanks for the response, when checking whether the user is authorized, it was said that he is authorized (Test account) `import firestore, { firebase } from '@react-native-firebase/firestore'; console.log(firebase.auth()) ` – HardKoT Jan 25 '22 at 09:47
  • Stack Overflow is English only. Please [edit] your question to translate, or check out [ru.SO]. – Adriaan Jan 25 '22 at 10:59
  • @Adriaan, edit ask. But I bad know english – HardKoT Jan 25 '22 at 11:28
  • Thanks! Not knowing English very well is not a problem, as long as others can understand you. Anyone can subsequently edit your question to correct grammar if necessary. If you feel more comfortable asking in Russian, feel free to ask on the Russian sister site instead, it's rather active. – Adriaan Jan 25 '22 at 11:31
  • @Adriaan, With Russian suite they offer the same thing, although it can't help in any way. This is my first time working with Firebase and everything worked for the first two weeks with standard rules, but today it gives an error. and I do not know why. Although they offer me to put true on all the rules. This does not help in any way for 6-7 hours I have been trying to understand, so I have already turned here. – HardKoT Jan 25 '22 at 11:54

1 Answers1

1

In firestore, if you got any permission denied. This is because firestore security rules.

Change your rules to:

service cloud.firestore {
 match /databases/{database}/documents {
  match /{document=**} {
   allow read, write: if true;
  }
 }
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Naseef m
  • 21
  • 2