【发布时间】:2018-11-05 09:51:48
【问题描述】:
在here 之后,我创建了一个简单的安全规则和云函数,调用它来查看用户名是否已经存在。问题是安全规则写入检查总是通过并且只是在该位置(/username_lookup/user1)设置新值。
当我尝试使用实时数据库规则模拟器在此位置写入时,它按预期工作,即写入被阻止。
有人能发现问题吗?
firebase 安全规则
"rules": {
"username_lookup": {
"$username": {
// not readable, cannot get a list of usernames!
// can only write if this username is not already in the db
".write": "!data.exists()",
// can only write my own uid into this index
".validate": "newData.val() === auth.uid"
}
}
}
还有云功能
var fb = admin.database().ref();
createUser(uid, username);
function createUser(userId, usrname) {
fb.child('username_lookup').child(usrname).set(userId, function(unerr) {
if(unerr) {
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({error: "the_error_code" }));
}
});
}
【问题讨论】:
标签: javascript firebase firebase-realtime-database firebase-security