0
我想檢查用戶名是否存在。Swift + Firebase - 檢查具有autoId的節點的值是否存在
但Xcode抱怨我的安全規則。
[Firebase/Database] [I-RDB034028]使用未指定的索引。考慮 加入「.indexOn」:‘個人資料/用戶名’AT /用戶您的安全規則 獲得更好的性能
如果我刪除‘$ UID’的Xcode不抱怨了,但我的腳本不工作得更好。
快照總是空,即使我進入一個存在於火力
用戶名我已經檢查了論壇,來自不同用戶想盡了各種辦法,但沒有固定我的問題,所以也許我做錯了什麼?
這是我的規則
{
"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())
})
}