首页 > 解决方案 > FirebaseErrorr: Missing or insufficient permissions happens, When trying to get snapShot

问题描述

I tried to get snapShot with React.js and Webpack, and had the error Uncaught (in promise) FirebaseError: Missing or insufficient permissions. Thank you very much in advance.

I suspected my webpack setting is something wrong to make the async request. However, when I tried the simple async request with the same setup, there is no issue. On top of this, Getting document also works correctly. I'm totally lost what I should do next.

//App.js

componentDidMount() {
    this.unsubscribeFromAuth = auth.onAuthStateChanged(async user => {
      this.setState({ user });
      await createUserProfDoc(user);
    });
  }

//FireBase code

export const firestore = firebase.firestore();
export const createUserProfDoc = async (userAuth, additionalData) => {
  if (!userAuth) {
    return;
  }
  const userRef = firestore.doc('users/123');
  const snapShot = await userRef.get();
  console.log(snapShot);
};

标签: reactjsfirebasegoogle-cloud-firestorefirebase-security

解决方案


如果错误来自您共享的代码,则用户似乎没有权限阅读 document users/123

您更有可能想要阅读用户的个人资料文档,该文件通常在其 UID 上定义/键入。在代码中是:

const userRef = firestore.collection('users').doc(user.uid);

推荐阅读