我有一个使用 Firebase 的聊天应用程序,它一直有
x 处的 setValue 失败:数据库错误:权限被拒绝
每次我输入消息时都会出错。
我已经将数据库设置为公开:
service cloud.firestore {
match /databases/{database}/documents {
match /{allPaths=**} {
allow read, write: if request.auth.uid != null;
}
}
}
这是我的聊天参考中的内容吗?
private void displayChat() {
ListView listOfMessage = findViewById(R.id.list_of_message);
Query query = FirebaseDatabase.getInstance().getReference();
FirebaseListOptions<Chat> options = new FirebaseListOptions.Builder<Chat>()
.setLayout(R.layout.list_item)
.setQuery(query, Chat.class)
.build();
adapter = new FirebaseListAdapter<Chat>(options) {
@Override
protected void populateView(View v, Chat model, int position) {
//Get reference to the views of list_item.xml
TextView messageText, messageUser, messageTime;
messageText = v.findViewById(R.id.message_text);
messageUser = v.findViewById(R.id.message_user);
messageTime = v.findViewById(R.id.message_time);
messageText.setText(model.getMessageText());
messageUser.setText(model.getMessageUser());
messageTime.setText(DateFormat.format("dd-MM-yyyy (HH:mm:ss)", model.getMessageTime()));
}
};
listOfMessage.setAdapter(adapter);
}
您的代码正在使用 Firebase 实时数据库,但您正在更改 Cloud Firestore 的安全规则。虽然这两个数据库都是 Firebase 的一部分,但它们完全不同,其中一个数据库的服务器端安全规则并不适用于另一个数据库。
当您进入 Firebase 控制台中的数据库面板时,您很可能会进入Cloud Firestore 规则 https://console.firebase.google.com/u/0/project/_/database/firestore/rules:
If you are on the Cloud Firestore rules in the Firebase console https://console.firebase.google.com/u/0/project/_/database/firestore/rules, you can change to the Realtime Database rules by clicking Cloud Firestore BETA at the top, and then selecting Realtime Database from the list.
您还可以直接转到实时数据库的安全规则,方法是单击这个链接 https://console.firebase.google.com/u/0/project/_/database/_/rules.
与您所拥有的实时数据库的安全规则相匹配的是:
{
"rules": {
".read": "auth.uid !== null",
".write": "auth.uid !== null"
}
}
这将授予任何经过身份验证的用户对整个数据库的完全读写访问权限。请阅读我对此问题的回答,了解有关此类规则的安全/风险权衡的更多信息:Firebase 电子邮件显示我的实时数据库存在不安全规则 https://stackoverflow.com/questions/51392059/firebase-email-saying-my-realtime-database-has-insecure-rules.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)