title: Firestore error -> Error: Missing or insufficient permissions
body: <p>I occasionally get this error in my application which utilizes firestore on the client frontend (JS Firebase/Firestore SDK library). This behaves like a rate limit issue I think, but my setup on Firebase is Blaze (pay as you go), so should I be seeing occasional issues like this? </p>
  
  <p>During my development, clearing my cache / waiting it out / switching sessions or browsers seems to get around the issue. Not sure why it occasionally happens or why the ditsing around would solve it. </p>
  
  <p>I currently have <code>firebase.auth().signOut()</code> implemented in my application, but whenever this happens, logging out and logging back in doesn't appear to solve the problem.</p>
  
  <p>Here's my developer console stacktrace for the issue:</p>
  
  <pre><code>index.js:2177 Firestore error -&gt; Error: Missing or insufficient permissions.
      at new FirestoreError (error.js:149)
      at JsonProtoSerializer../node_modules/@firebase/firestore/dist/esm/src/remote/serializer.js.JsonProtoSerializer.fromRpcStatus (serializer.js:93)
      at JsonProtoSerializer../node_modules/@firebase/firestore/dist/esm/src/remote/serializer.js.JsonProtoSerializer.fromWatchChange (serializer.js:536)
      at PersistentListenStream../node_modules/@firebase/firestore/dist/esm/src/remote/persistent_stream.js.PersistentListenStream.onMessage (persistent_stream.js:389)
      at persistent_stream.js:331
      at persistent_stream.js:306
      at async_queue.js:83
      at &lt;anonymous&gt;
  __stack_frame_overlay_proxy_console__ @ index.js:2177
  (anonymous) @ SideMenu.js:91
  Promise rejected (async)
  componentDidUpdate @ SideMenu.js:88
  commitLifeCycles @ react-dom.development.js:11517
  commitAllLifeCycles @ react-dom.development.js:12294
  callCallback @ react-dom.development.js:1299
  invokeGuardedCallbackDev @ react-dom.development.js:1338
  invokeGuardedCallback @ react-dom.development.js:1195
  commitAllWork @ react-dom.development.js:12415
  workLoop @ react-dom.development.js:12687
  callCallback @ react-dom.development.js:1299
  invokeGuardedCallbackDev @ react-dom.development.js:1338
  invokeGuardedCallback @ react-dom.development.js:1195
  performWork @ react-dom.development.js:12800
  scheduleUpdateImpl @ react-dom.development.js:13185
  scheduleUpdate @ react-dom.development.js:13124
  enqueueSetState @ react-dom.development.js:9646
  ./node_modules/react/cjs/react.development.js.ReactComponent.setState @ react.development.js:218
  onStateChange @ connectAdvanced.js:205
  dispatch @ createStore.js:173
  (anonymous) @ Utils.js:162
  Promise resolved (async)
  (anonymous) @ Utils.js:146
  getGoogleCloudProjectsWithPromise @ Utils.js:115
  (anonymous) @ AppMenu.js:126
  Promise resolved (async)
  finalizeLogin @ AppMenu.js:123
  e.g @ auth.js:23
  Yb @ auth.js:26
  Ub @ auth.js:26
  ./node_modules/@firebase/auth/dist/auth.js.h.Mb @ auth.js:25
  Cb @ auth.js:19
  Promise resolved (async)
  zb @ auth.js:18
  yb @ auth.js:18
  Vb @ auth.js:25
  Eb @ auth.js:24
  (anonymous) @ auth.js:19
  (anonymous) @ auth.js:142
  (anonymous) @ auth.js:138
  qd @ auth.js:45
  G @ auth.js:44
  ef @ auth.js:77
  ./node_modules/@firebase/auth/dist/auth.js.h.fc @ auth.js:75
  ./node_modules/@firebase/auth/dist/auth.js.h.zb @ auth.js:75
  XMLHttpRequest.send (async)
  (anonymous) @ VM7143:1
  Ye @ auth.js:73
  ./node_modules/@firebase/auth/dist/auth.js.Ch.m @ auth.js:138
  Kh @ auth.js:137
  (anonymous) @ auth.js:142
  z @ auth.js:19
  Qh @ auth.js:142
  (anonymous) @ auth.js:153
  e.g @ auth.js:23
  Yb @ auth.js:26
  Ub @ auth.js:26
  ./node_modules/@firebase/auth/dist/auth.js.h.Mb @ auth.js:25
  Cb @ auth.js:19
  Promise resolved (async)
  zb @ auth.js:18
  yb @ auth.js:18
  Vb @ auth.js:25
  Eb @ auth.js:24
  A @ auth.js:20
  ./node_modules/@firebase/auth/dist/auth.js.h.get @ auth.js:181
  ./node_modules/@firebase/auth/dist/auth.js.pj.get @ auth.js:184
  ml @ auth.js:240
  ll @ auth.js:239
  ul @ auth.js:242
  (anonymous) @ auth.js:286
  ./node_modules/@firebase/app/dist/esm/src/firebaseApp.js.FirebaseAppImpl._getService @ firebaseApp.js:116
  FirebaseAppImpl.(anonymous function) @ firebaseApp.js:303
  (anonymous) @ auth.js:286
  (anonymous) @ firebaseApp.js:323
  callAppHooks @ firebaseApp.js:316
  initializeApp @ firebaseApp.js:247
  ./src/redux/factory.js @ factory.js:49
  __webpack_require__ @ bootstrap 6a68f7b55db27319f480:678
  fn @ bootstrap 6a68f7b55db27319f480:88
  ./src/components/AppMenu.js @ Utils.js:170
  __webpack_require__ @ bootstrap 6a68f7b55db27319f480:678
  fn @ bootstrap 6a68f7b55db27319f480:88
  ./src/App.js @ fetch.js:461
  __webpack_require__ @ bootstrap 6a68f7b55db27319f480:678
  fn @ bootstrap 6a68f7b55db27319f480:88
  ./src/index.js @ Start.js:50
  __webpack_require__ @ bootstrap 6a68f7b55db27319f480:678
  fn @ bootstrap 6a68f7b55db27319f480:88
  0 @ index.css?b74f:26
  __webpack_require__ @ bootstrap 6a68f7b55db27319f480:678
  ./node_modules/@firebase/app/dist/esm/index.js.Object.defineProperty.value @ bootstrap 6a68f7b55db27319f480:724
  (anonymous) @ bundle.js:728
  index.js:2177 Firestore error -&gt; Error: Missing or insufficient permissions.
      at new FirestoreError (error.js:149)
      at JsonProtoSerializer../node_modules/@firebase/firestore/dist/esm/src/remote/serializer.js.JsonProtoSerializer.fromRpcStatus (serializer.js:93)
      at JsonProtoSerializer../node_modules/@firebase/firestore/dist/esm/src/remote/serializer.js.JsonProtoSerializer.fromWatchChange (serializer.js:536)
      at PersistentListenStream../node_modules/@firebase/firestore/dist/esm/src/remote/persistent_stream.js.PersistentListenStream.onMessage (persistent_stream.js:389)
      at persistent_stream.js:331
      at persistent_stream.js:306
      at async_queue.js:83
      at &lt;anonymous&gt;
  __stack_frame_overlay_proxy_console__ @ index.js:2177
  (anonymous) @ SideMenu.js:91
  Promise rejected (async)
  componentDidUpdate @ SideMenu.js:88
  commitLifeCycles @ react-dom.development.js:11517
  commitAllLifeCycles @ react-dom.development.js:12294
  callCallback @ react-dom.development.js:1299
  invokeGuardedCallbackDev @ react-dom.development.js:1338
  invokeGuardedCallback @ react-dom.development.js:1195
  commitAllWork @ react-dom.development.js:12415
  workLoop @ react-dom.development.js:12687
  callCallback @ react-dom.development.js:1299
  invokeGuardedCallbackDev @ react-dom.development.js:1338
  invokeGuardedCallback @ react-dom.development.js:1195
  performWork @ react-dom.development.js:12800
  scheduleUpdateImpl @ react-dom.development.js:13185
  scheduleUpdate @ react-dom.development.js:13124
  enqueueSetState @ react-dom.development.js:9646
  ./node_modules/react/cjs/react.development.js.ReactComponent.setState @ react.development.js:218
  onStateChange @ connectAdvanced.js:205
  dispatch @ createStore.js:173
  (anonymous) @ AppMenu.js:128
  Promise resolved (async)
  (anonymous) @ AppMenu.js:126
  Promise resolved (async)
  finalizeLogin @ AppMenu.js:123
  e.g @ auth.js:23
  Yb @ auth.js:26
  Ub @ auth.js:26
  ./node_modules/@firebase/auth/dist/auth.js.h.Mb @ auth.js:25
  Cb @ auth.js:19
  Promise resolved (async)
  zb @ auth.js:18
  yb @ auth.js:18
  Vb @ auth.js:25
  Eb @ auth.js:24
  (anonymous) @ auth.js:19
  (anonymous) @ auth.js:142
  (anonymous) @ auth.js:138
  qd @ auth.js:45
  G @ auth.js:44
  ef @ auth.js:77
  ./node_modules/@firebase/auth/dist/auth.js.h.fc @ auth.js:75
  ./node_modules/@firebase/auth/dist/auth.js.h.zb @ auth.js:75
  XMLHttpRequest.send (async)
  (anonymous) @ VM7143:1
  Ye @ auth.js:73
  ./node_modules/@firebase/auth/dist/auth.js.Ch.m @ auth.js:138
  Kh @ auth.js:137
  (anonymous) @ auth.js:142
  z @ auth.js:19
  Qh @ auth.js:142
  (anonymous) @ auth.js:153
  e.g @ auth.js:23
  Yb @ auth.js:26
  Ub @ auth.js:26
  ./node_modules/@firebase/auth/dist/auth.js.h.Mb @ auth.js:25
  Cb @ auth.js:19
  Promise resolved (async)
  zb @ auth.js:18
  yb @ auth.js:18
  Vb @ auth.js:25
  Eb @ auth.js:24
  A @ auth.js:20
  ./node_modules/@firebase/auth/dist/auth.js.h.get @ auth.js:181
  ./node_modules/@firebase/auth/dist/auth.js.pj.get @ auth.js:184
  ml @ auth.js:240
  ll @ auth.js:239
  ul @ auth.js:242
  (anonymous) @ auth.js:286
  ./node_modules/@firebase/app/dist/esm/src/firebaseApp.js.FirebaseAppImpl._getService @ firebaseApp.js:116
  FirebaseAppImpl.(anonymous function) @ firebaseApp.js:303
  (anonymous) @ auth.js:286
  (anonymous) @ firebaseApp.js:323
  callAppHooks @ firebaseApp.js:316
  initializeApp @ firebaseApp.js:247
  ./src/redux/factory.js @ factory.js:49
  __webpack_require__ @ bootstrap 6a68f7b55db27319f480:678
  fn @ bootstrap 6a68f7b55db27319f480:88
  ./src/components/AppMenu.js @ Utils.js:170
  __webpack_require__ @ bootstrap 6a68f7b55db27319f480:678
  fn @ bootstrap 6a68f7b55db27319f480:88
  ./src/App.js @ fetch.js:461
  __webpack_require__ @ bootstrap 6a68f7b55db27319f480:678
  fn @ bootstrap 6a68f7b55db27319f480:88
  ./src/index.js @ Start.js:50
  __webpack_require__ @ bootstrap 6a68f7b55db27319f480:678
  fn @ bootstrap 6a68f7b55db27319f480:88
  0 @ index.css?b74f:26
  __webpack_require__ @ bootstrap 6a68f7b55db27319f480:678
  ./node_modules/@firebase/app/dist/esm/index.js.Object.defineProperty.value @ bootstrap 6a68f7b55db27319f480:724
  (anonymous) @ bundle.js:728
  index.js:2177 Firestore error -&gt; Error: Missing or insufficient permissions.
      at new FirestoreError (error.js:149)
      at JsonProtoSerializer../node_modules/@firebase/firestore/dist/esm/src/remote/serializer.js.JsonProtoSerializer.fromRpcStatus (serializer.js:93)
      at JsonProtoSerializer../node_modules/@firebase/firestore/dist/esm/src/remote/serializer.js.JsonProtoSerializer.fromWatchChange (serializer.js:536)
      at PersistentListenStream../node_modules/@firebase/firestore/dist/esm/src/remote/persistent_stream.js.PersistentListenStream.onMessage (persistent_stream.js:389)
      at persistent_stream.js:331
      at persistent_stream.js:306
      at async_queue.js:83
      at &lt;anonymous&gt;
  __stack_frame_overlay_proxy_console__ @ index.js:2177
  (anonymous) @ SideMenu.js:91
  Promise rejected (async)
  componentDidUpdate @ SideMenu.js:88
  commitLifeCycles @ react-dom.development.js:11517
  commitAllLifeCycles @ react-dom.development.js:12294
  callCallback @ react-dom.development.js:1299
  invokeGuardedCallbackDev @ react-dom.development.js:1338
  invokeGuardedCallback @ react-dom.development.js:1195
  commitAllWork @ react-dom.development.js:12415
  workLoop @ react-dom.development.js:12687
  callCallback @ react-dom.development.js:1299
  invokeGuardedCallbackDev @ react-dom.development.js:1338
  invokeGuardedCallback @ react-dom.development.js:1195
  performWork @ react-dom.development.js:12800
  scheduleUpdateImpl @ react-dom.development.js:13185
  scheduleUpdate @ react-dom.development.js:13124
  enqueueSetState @ react-dom.development.js:9646
  ./node_modules/react/cjs/react.development.js.ReactComponent.setState @ react.development.js:218
  onStateChange @ connectAdvanced.js:205
  dispatch @ createStore.js:173
  routeAfterLogin @ AppMenu.js:200
  (anonymous) @ AppMenu.js:129
  Promise resolved (async)
  (anonymous) @ AppMenu.js:126
  Promise resolved (async)
  finalizeLogin @ AppMenu.js:123
  e.g @ auth.js:23
  Yb @ auth.js:26
  Ub @ auth.js:26
  ./node_modules/@firebase/auth/dist/auth.js.h.Mb @ auth.js:25
  Cb @ auth.js:19
  Promise resolved (async)
  zb @ auth.js:18
  yb @ auth.js:18
  Vb @ auth.js:25
  Eb @ auth.js:24
  (anonymous) @ auth.js:19
  (anonymous) @ auth.js:142
  (anonymous) @ auth.js:138
  qd @ auth.js:45
  G @ auth.js:44
  ef @ auth.js:77
  ./node_modules/@firebase/auth/dist/auth.js.h.fc @ auth.js:75
  ./node_modules/@firebase/auth/dist/auth.js.h.zb @ auth.js:75
  XMLHttpRequest.send (async)
  (anonymous) @ VM7143:1
  Ye @ auth.js:73
  ./node_modules/@firebase/auth/dist/auth.js.Ch.m @ auth.js:138
  Kh @ auth.js:137
  (anonymous) @ auth.js:142
  z @ auth.js:19
  Qh @ auth.js:142
  (anonymous) @ auth.js:153
  e.g @ auth.js:23
  Yb @ auth.js:26
  Ub @ auth.js:26
  ./node_modules/@firebase/auth/dist/auth.js.h.Mb @ auth.js:25
  Cb @ auth.js:19
  Promise resolved (async)
  zb @ auth.js:18
  yb @ auth.js:18
  Vb @ auth.js:25
  Eb @ auth.js:24
  A @ auth.js:20
  ./node_modules/@firebase/auth/dist/auth.js.h.get @ auth.js:181
  ./node_modules/@firebase/auth/dist/auth.js.pj.get @ auth.js:184
  ml @ auth.js:240
  ll @ auth.js:239
  ul @ auth.js:242
  (anonymous) @ auth.js:286
  ./node_modules/@firebase/app/dist/esm/src/firebaseApp.js.FirebaseAppImpl._getService @ firebaseApp.js:116
  FirebaseAppImpl.(anonymous function) @ firebaseApp.js:303
  (anonymous) @ auth.js:286
  (anonymous) @ firebaseApp.js:323
  callAppHooks @ firebaseApp.js:316
  initializeApp @ firebaseApp.js:247
  ./src/redux/factory.js @ factory.js:49
  __webpack_require__ @ bootstrap 6a68f7b55db27319f480:678
  fn @ bootstrap 6a68f7b55db27319f480:88
  ./src/components/AppMenu.js @ Utils.js:170
  __webpack_require__ @ bootstrap 6a68f7b55db27319f480:678
  fn @ bootstrap 6a68f7b55db27319f480:88
  ./src/App.js @ fetch.js:461
  __webpack_require__ @ bootstrap 6a68f7b55db27319f480:678
  fn @ bootstrap 6a68f7b55db27319f480:88
  ./src/index.js @ Start.js:50
  __webpack_require__ @ bootstrap 6a68f7b55db27319f480:678
  fn @ bootstrap 6a68f7b55db27319f480:88
  0 @ index.css?b74f:26
  __webpack_require__ @ bootstrap 6a68f7b55db27319f480:678
  ./node_modules/@firebase/app/dist/esm/index.js.Object.defineProperty.value @ bootstrap 6a68f7b55db27319f480:724
  (anonymous) @ bundle.js:728
  </code></pre>
  
  <p>Here are my datastore security rules:</p>
  
  <pre><code>service cloud.firestore {
    match /databases/{database}/documents {
      match /{document=**} {
        allow read, write: if false;
      }
      match /dev/organizations/{orgId} {
          allow read;
        match /beacon-providers/{providerId} {
          // allow read, write: if auth.ordId = orgId
          // @TODO also check if user is an admin in the current org
          allow read, write: if orgId == 'incubation'
        }    
      }
      match /organizations/{orgId} {
        allow read, write: if orgId == 'incubation';
        match /beacon-providers {
          allow read, write;
          match /{providerId} {
                      //allow read: if resource.data.user_uid == request.auth.uid;
                      allow read,write;
          }
        }
      }
    }
  }
  </code></pre>