【发布时间】:2018-02-09 02:19:31
【问题描述】:
我正在尝试创建对我的 firebase 数据库的引用并发送 user.uid,但不写入数据库中的该路径。这可能吗?
var dbObj = firebase.database().ref().child(`match/${user.uid}/${randomID}`);
var milliseconds = (new Date).getTime();
return dbObj.update({
// Set the interested value in the db
[milliseconds]: 'text'
});
所以我使用 user.uid 来验证用户是否通过 firebase 数据库规则有效登录。我将它与 $uid 匹配,这很有效。
"match": {
"$uid": {
".write": "auth.uid == $uid",
".read": "auth.uid == $uid",
}
}
但我想写入的数据库位置是:../match/randomID/otherData INSTEAD of ../match/userID/randomID/otherData
【问题讨论】:
-
我不明白你想在这里完成什么。这听起来像是一个我不清楚问题是什么的解决方案(所谓的XY problem)。您能否换句话说解释一下这段代码的目标/预期结果是什么?例如。如果你把这段 sn-p 的代码想象成一个函数,那这个函数的名字是什么?
-
我问有没有办法将 uid 发送到 firebase 进行规则身份验证,但不写入包含 uid 的数据库路径。示例在问题的最后一行。
标签: javascript firebase-realtime-database firebase-security