I am trying to access an authenticated users document and add a parameter to the document within the "users" collection if the uid matches.
The error message is as follow:
Error Domain=com.firebase Code=1 "Permission denied" UserInfo={NSLocalizedDescription=Permission denied}.
Whilst the error suggests it is a permission issue, when I change the child collection to an invalid path, the same error shows. I have also changed the rules to allow read and write regardless of authentication and the same error is shown.
Code to save the data:
//save the user data to firebase
func saveData(){
//check if user is signed in
guard let userID = Auth.auth().currentUser?.uid else {
return
}
ref = Database.database().reference()
self.ref.child("users").child(userID).setValue(["name": userName) {
(error:Error?, ref:DatabaseReference) in
if let error = error {
print("Data could not be saved: \(error).")
} else {
print("Data saved successfully!")
}
}
}
Database rules:
service cloud.firestore {
match /databases/{database}/documents {
// Make sure the uid of the requesting user matches name of the user
// document. The wildcard expression {userId} makes the userId variable
// available in rules.
match /users/{userId} {
allow read, update, write, delete: if request.auth.uid == userId;
}
}
}