Firebase rules when user log out 'Missing or insufficient permissions. Error: Missing or insufficient permissions'

孤街醉人 提交于 2021-01-20 12:53:45

问题


Error :

'Error with profile listener: Missing or insufficient permissions. Error: Missing or insufficient permissions.'

My app is a project manager built using Reactjs, Redux, Firebase. Could you tell me why it gives this error when the user logs out and how to solve it?

My rules:

service cloud.firestore {
  match /databases/{database}/documents {
  // Match any {project} document in the 'projects' collection
    match /projects/{project} {
     // Allow signed in users to read write projects
      allow read, write: if request.auth.uid != null; 
    }
    // Match any {user} document in the 'users' collection
    match /users/{user} {
     // Allow users to signup and create an account
      allow create;
      // Allow signed in users to read project details - who create project and when)
      allow read: if request.auth.uid != null;
      // Allow signed in user to update his info only if signed in id == user document id
      allow update, delete: if request.auth.uid == user;
    }
  }
}

回答1:


If this happens when you log out, that means you still have an onSnapshot listener attached to a collection that requires a user to be authenticated. When you log out, that listener becomes invalid, and thus the security rules reject it.

To get rid of the message, remove all such listeners before the user logs out. In your specific case, it seems to be a problem with the "profile listener".




回答2:


When you logout any existing subscribes will still be subscribed and you will get that error. You can unsubscribe before logout or send the user to another page and logout from there. When you send a the user to another page the subscribes should be garbage collected. Thats how it works in angular components at least, not sure about react.



来源:https://stackoverflow.com/questions/54599250/firebase-rules-when-user-log-out-missing-or-insufficient-permissions-error-mi

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