title: Firestore: userId rule
body: <p><strong>I cannot get this firestore rule to work.</strong></p>
  
  <p>I want to write/read to <code>user-read-only/USER-ID-HERE/business/settings</code></p>
  
  <pre><code>service cloud.firestore {
    match /databases/{database}/documents {
  
      match /user-read-only/{userId} {
        allow read, update, delete: if request.auth.uid == userId;
        allow create: if request.auth.uid != null;
  
        match /{document=**} {
          allow read, update, delete: if request.auth.uid == userId;
          allow create: if request.auth.uid != null;
        }
      }
    }
  }
  </code></pre>
  
  <p>I continue to get the message </p>
  
  <blockquote>
    <p>FirebaseError: Missing or insufficient permissions.</p>
  </blockquote>
  
  <p>I have tried many different approaches with the simulator and they are all successful, but I can’t repro from my app.</p>
  
  <hr>
  
  <ul>
  <li>Does anything look incorrect above?</li>
  <li>Can the above be simplified? I would like the user to be able to control everything beyond <code>{userId}</code></li>
  <li>How do I know if <code>request.auth.uid</code> and <code>userId</code> are populating properly?</li>
  </ul>
  
  <hr>
  
  <p>This works</p>
  
  <pre><code>service cloud.firestore {
    match /databases/{database}/documents {
  
      match /{userId}/{document=**} {
        allow read, write;
      }
    }
  }
  </code></pre>
  
  <p>This does not work</p>
  
  <pre><code>service cloud.firestore {
    match /databases/{database}/documents {
  
      match /{userId}/{document=**} {
        allow read, write: if request.auth.uid == userId;
      }
    }
  }
  </code></pre>