android - 在 Firebase Android 中读写
问题描述
我正在使用具有以下规则的 Firebase 实时数据库
{
"rules": {
"users": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
}
}
}
我在数据库中编写的代码是
mDatabase = FirebaseDatabase.getInstance().getReference("OWNER_DATA");
String id = mDatabase.push().getKey();
OwnerSignup ownerSignup = new OwnerSignup(id, name, email, phoneNumber);
mDatabase.child("MY_DATA").setValue(ownerSignup);
如果我将规则更改为
read:"false"
write:"false"
我可以推送数据,但使用上述规则,我无法在数据中插入值。请帮我解决这个问题。
以及如何在我的 API 为“ https://rent-c-246c0.firebaseio.com/ ”的 Postman 中使用 API 调用它
我尝试在邮递员中使用以下给定的 API https://rent-c-246c0.firebaseio.com/OWNER_DATA.json
在这里我想传递我的 auth.uid 令牌
解决方案
如果您使用以下规则:
read:"false" and write:"false"
这意味着您无法检索或向数据库添加数据。
如果您使用:
{
"rules": {
"some_path": {
"$uid": {
// Allow only authenticated content owners access to their data
".read": "request.auth.uid == uid"
".write": "request.auth.uid == uid"
}
}
}
}
然后,这些规则将访问权限仅限于经过身份验证的内容所有者。数据只能由一个用户读写,数据路径包含用户的ID。
https://firebase.google.com/docs/rules/basics#content-owner_only_access
推荐阅读
- javascript - 在下拉元素中按字母顺序对 API 结果进行排序(请仅使用 Javascript)
- python - Heroku:Python Django 部署突然失败
- python-3.x - 在熊猫数据框中创建聚合列
- javascript - 在 React 中渲染新组件 onclick
- python - 如何从数据集中删除 EXIF 数据?
- api - 从 Google 电子表格请求 BigQuery API 会产生错误
- python-3.x - 使用python提取zip文件并保留顶级文件夹
- .net-core - 使用带有 samba 挂载的 C# dotnet core CENTOS 对 File.Copy 的权限被拒绝
- firebase - Firebase 实时数据库 + nodejs(auth.uid === $uid 规则)
- powershell - Powershell - 如何添加列宽