firestore : Missing or insufficient permissions

╄→гoц情女王★ 提交于 2021-01-28 02:06:42

问题


I'm using Role ( allow read ,write : if request.auth.uid != null ) when I logged in I get data it's ok , but when I log out the user I get the error : Missing or insufficient permissions. first I thought it was because of I didn't unsubscribe the Observable I tried (rxjs/operator/takeWhile) even if I used async pipe, I got the same error.


回答1:


if you're logged out then request.auth.id == null, therefore, your read rule returns false. try changing to:

allow read;
allow create: if request.auth.uid != null; 

This allows anyone to read and only authenticated users to create. You'll usually only want authors to update. For that you'll need to save the author's uid on the document as a property like userid, then you can update your rules like this:

match /myCollection/{document=**} {
  allow read;
  allow create: if request.auth.uid != null; 
  allow update: if isOwner();
}

function existingData() {
  return resource.data
}

function isOwner() {
  return request.auth.uid == existingData().userid;
}


来源:https://stackoverflow.com/questions/49623045/firestore-missing-or-insufficient-permissions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!