I'm trying to retrieve data from a firebase database, but to secure the data I should give the API the user's id, and it should answer with the user's name.
Here is my database format:
users : {
"x0001": "John"
"x0002": "Samuel"
"x0003": "Rachel"
}
And Here are the constraints respecting the documentation https://firebase.google.com/docs/database/security/securing-data
{
"rules": {
"users": {
".read": "query.equalTo != null",
".write": false
}
}
}
Here is the method to access to my database
func isUserExists(userId: String) {
Database.database().reference().child("users")
.queryOrderedByKey()
.queryEqual(toValue: userId)
.observeSingleEvent(of: .value, with: { (snapshot) in
print(snapshot.value as? String)
}){ (error) in
print("error: \(error.localizedDescription)")
}
}
When I call this method for example with a userId
isUserExists(userId: "x0001")
output
error : Permission Denied
When I test with no constraints it works well, so I guess the request is well written but it does not respect this constraint
".read": "query.equalTo != null"
Thanks