Title: Firestore: FirebaseError: Missing or insufficient permissions
Tags: javascript;typescript;firebase;google-cloud-firestore;firebase-security
Question: I have the following rule:
```rules_version = '2';
service cloud.firestore {

    match /documents/{any} {
        allow read, write: if request.auth.uid != null
    }

    match /users/{any} {
        allow read, write: if request.auth.uid != null
    }
}
```
So basically, I want users that are authenticated to be able to read/write to the ```users``` and ```documents``` collections. But I try to write when I create a user and signin:
```                const registerRes = await firebase
                    .auth()
                    .createUserWithEmailAndPassword(email, password);
                await registerRes.user.updateProfile({
                    displayName: fullName
                });
                registerRes.user.sendEmailVerification();
                await firebase.firestore().collection('users').doc(registerRes?.user?.uid).set({...someStuff});
```
But I get an error:
```FirebaseError: Missing or insufficient permissions.
```
Not sure what I'm doing wrong. Any help would be greatly appreciated - thanks!


Here is the accepted answer: As explained in the doc, you need to include your path specific rules in a ```match /databases/{database}/documents``` block like:
```rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {

    match /documents/{any} {
        allow read, write: if request.auth.uid != null
    }

    match /users/{any} {
        allow read, write: if request.auth.uid != null
    }


  }
}
```

Side note: Be aware that rules that are only based on ```request.auth.uid != null``` are not really securing your DB, see this SO answer.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2021:00:05/25/21', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><typescript><firebase><google-cloud-firestore><firebase-security>', 'Title': 'Firestore: FirebaseError: Missing or insufficient permissions', 'ViewCount': 88, 'id': 67688203, 'user_AboutMe': '<p>Building products + communities with code. Entrepreneur with more losses than wins. Lifelong learner with a passion for AI+ML / #Bitcoin.</p>\n', 'user_AccountId': 86204.0, 'user_DisplayName': 'Shamoon', 'user_Reputation': 39359.0, 'user_Views': 4514.0, 'user_id': 239879.0}}