【发布时间】:2017-12-05 16:53:45
【问题描述】:
我想检查用户名是否存在。
但是 Xcode 抱怨我的安全规则。
[Firebase/Database][I-RDB034028] 使用未指定的索引。考虑 将 /users 处的 ".indexOn": "profile/username" 添加到您的安全规则中 为了更好的性能
如果我删除“$uid”,Xcode 不再抱怨,但我的脚本不能更好地运行。
即使我输入存在于 firebase 中的用户名,快照也始终为空
我已经检查了论坛并尝试了来自不同用户的不同解决方案,但没有解决我的问题,所以也许我做错了什么?
这是我的规则
{
"rules": {
".read": "auth != null",
".write": "auth != null",
"users": {
"$uid": {
"profile":{
".indexOn":["username"]
}
}
}
}
}
这是我的脚本
//check if username exist in the database
static func checkIfUsernameExist(username: String, callback: @escaping (_ found: Bool) -> Void){
print(username)
let databaseRef = Database.database().reference(withPath: "users")
databaseRef.queryOrdered(byChild: "profile/username").queryEqual(toValue: username).observeSingleEvent(of: .value, with: { (snapshot) in
print(snapshot)
callback(snapshot.exists())
})
}
【问题讨论】:
标签: ios swift firebase firebase-realtime-database