I am having some issues with Firebase security rules. I want any user to be able to create an account using my iOS app at the same time once he or she establishes the account I want to have two nodes one is private, and one is public. I want the public to be accessed by anyone, including the user its self, but the user that created the account only accesses the private node. I have tried a lot of things, but none of my work seems to work. I want to fetch all the public node values by just having a link without knowing the uid of each user
1- Anyone can create an account 2- Only the user can access his own private node 3- A link where I can fetch all of the user's public node only
Thank you!!!!
for example, I would like to fetch all the users https://id.firebaseio.com/Ireland.json
Here is some of my work
{
"rules": {
"Ireland": {
"users": {
"$uid": {
"private": {
".read": "auth != null && auth.uid == $uid",
".write": "auth != null && auth.uid == $uid",
},
"public": {
".read": true,
".write": "auth != null && auth.uid == $uid",
},
},
},
},
},
}
here is my swift code, but every time I try to create an account it says permission denied
guard let uid = result?.user.uid else { return }
let privateValues = ["email": email, "username": username, "password": password, "profileImageUrl": profileImageUrl, "country": "Ireland"]
let publicValues = ["username": username, "profileImageUrl": profileImageUrl]
let values = [uid: ["private": privateValues, "public": publicValues]]
Database.database().reference().child("Ireland").child("users").updateChildValues(values, withCompletionBlock: { (error, reference) in
if let error = error {
print("Failed to save user info to database: ", error)
self.signUpButton.wiggle()
return
}