我正在做一个在线图书馆系统,它在实时数据库中存储文件名,书的下载url(从firebase存储器)和用户的authd.uid,我想做的就是更新数据库规则并只允许用户将uid存储在数据中以访问数据
这是我的javascript代码,可将值存储在数据库中,对我有用 但问题是用户无法读取数据
const database = firebase.database();
const postKey=database.ref(postBook+'/').push().key;
const postData={
url:downloadURL,
name:bookFile.name,
uid:user.uid
};
updates[postBook+'/'+postKey]=postData;
firebase.database().ref().update(updates);
这是我的数据库的样子:
polsdatabase-f8594
New Microsoft Excel Worksheet
-LnrUtJIMHQHYfrfZQ7Z
name: "New Microsoft Excel Worksheet.xlsx"
uid: "Sju1GhAo24PEvZ1tjmVNKwvYnIy1"
url: "https://firebasestorage.googleapis.com/v0/b/pol..."
New Text Document
-LnrWCA8dYwx6STtwjZT
name: "New Text Document.txt"
uid: "Sju1GhAo24PEvZ1tjmVNKwvYnIy1"
url: "https://firebasestorage.googleapis.com/v0/b/pol..."
personal online library
-LnrW3gbE24_ifGE6JZL
name: "personal online library.txt"
uid: "Sju1GhAo24PEvZ1tjmVNKwvYnIy1"
url: "https://firebasestorage.googleapis.com/v0/b/pol..."
这是我尝试处理数据库规则的方法,但对我而言不起作用
{
/* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */
"rules": {
".read": "data.child('uid').val() == auth.uid",
".write": "auth.uid != null"
}
}