reactjs - 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);
};
解决方案
如果错误来自您共享的代码,则用户似乎没有权限阅读 document users/123
。
您更有可能想要阅读用户的个人资料文档,该文件通常在其 UID 上定义/键入。在代码中是:
const userRef = firestore.collection('users').doc(user.uid);
推荐阅读
- css - 如何在 Appmaker MultiSelect 小部件中设置选项样式
- c++ - 将 lambda 函数转换为具有混合 lambda-introducer 和参数列表的函子结构
- sql - codeigniter 应用程序的 sql 文件的位置
- xpath - Xpath 规则:尝试在网页上的特定标题标签下提取链接列表
- javascript - 选择downdown 1时如何更改选择下拉值?
- graphql - vue-apollo 是否可以从 Playground 返回不同的结果?
- swift - 从用户输入刷新 UIPicker
- mysql - 使用 DISTINCT 关键字难以将 GROUP_CONCAT 查询从 MySQL 转换为 H2
- python - 如何比较不同格式的地理位置?
- kubernetes - 在 azure kubernetes 中设置入口控制器