Javascript Firebase:缺少或权限不足

Javascript Firebase:缺少或权限不足,javascript,firebase,react-native,firebase-authentication,firebase-security,Javascript,Firebase,React Native,Firebase Authentication,Firebase Security,在我刚刚启动应用程序后,我没有登录,我尝试按id阅读文档: static async getUserByUID(uid) { let ref = firebase.firestore().collection("users"); let user = await ref.doc(uid).get() return user } 我得到一个错误: Missing or insufficien

在我刚刚启动应用程序后,我没有登录,我尝试按id阅读文档:

static async getUserByUID(uid) {

        let ref = firebase.firestore().collection("users");
        let user = await ref.doc(uid).get()
        
        return user
        
}
我得到一个错误:

Missing or insufficient permissions.
* http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:184506:21 in e
- node_modules/@firebase/firestore/dist/index.cjs.js:1:23672 in t.prototype.Vt
- node_modules/@firebase/firestore/dist/index.cjs.js:1:31796 in t.ee
- node_modules/@firebase/firestore/dist/index.cjs.js:1:148981 in <global>
- node_modules/@firebase/firestore/dist/index.cjs.js:1:48518 in e
- node_modules/promise/setimmediate/core.js:37:14 in tryCallOne
- node_modules/promise/setimmediate/core.js:123:25 in setImmediate$argument_0
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:146:14 in _callTimer
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:194:17 in _callImmediatesPass
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:458:30 in callImmediates
* [native code]:null in callImmediates
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:407:6 in __callImmediates
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:143:6 in __guard$argument_0
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:384:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:142:17 in __guard$argument_0
* [native code]:null in flushedQueue
* [native code]:null in callFunctionReturnFlushedQueue

如果我打开所有权限都正常工作,有什么建议吗?

您的规则要求用户登录(使用Firebase身份验证)才能访问数据。错误消息表示用户在尝试加载数据时未登录

解决方案是在加载数据之前使用Firebase身份验证登录用户。例如:

await auth().signInAnonymously()
let ref = firebase.firestore().collection("users");
let user = await ref.doc(uid).get()

从你的评论来看,你似乎对语言规则感到困惑。要允许对任何人进行读取,并且只允许对进行身份验证的用户进行写入,请执行以下操作:

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

但是读是允许的,只写需要身份验证,或者我遗漏了什么?是的,这不是你目前的规则。我在回答中加了一个解释。
allow read: if true;
allow write: if request.auth.uid != null;