I have to get a user's id by providing its email. My structure is:
users
-Wc1EtcYzZSMPCtWZ8wRb8RzNXqg2
-email: "batuarslan@gmail.com"
-lists
slid: "-LJsrWDfMPNcs_NjVYBM"
uid: "Wc1EtcYzZSMPCtWZ8wRb8RzNXqg2"
Is there a way to do this? Or do I have to restructure my tree in another way? My code:
func userLookUpByEmail (email: String, completionHandler: @escaping (_ result: String) -> Void) {
var userId : String = ""
usersRef.queryOrdered(byChild: "email").queryEqual(toValue: email).observeSingleEvent(of: .value, with: { snapshot in
if snapshot.value != nil {
userId = snapshot.key
}
else {
userId = "nil"
}
completionHandler(userId)
})
}
func userLookUpByEmail (email: String, completionHandler: @escaping (_ result: String) -> Void) {
var userId : String = ""
usersRef.queryOrdered(byChild: "email")
.queryEqual(toValue: email)
.observeSingleEvent(of: .value, with: { snapshot in
if snapshot.value != nil {
userId = snapshot.key
}
else {
userId = "nil"
}
completionHandler(userId)
})
}