3
votes

I am new to app programming. I finally got my app to work, but when I try to write data to firebase it gets denied? I even set the rules to true so that anyone can read and write data.

I cant figure out what is wrong?

2017-09-12 10:52:26.584 Smart-app[3232] [Firebase/Database][I-RDB038012] setValue: or removeValue: at /users failed: permission_denied

I am using this command to write data:

@IBAction func GemKunde(sender: UIButton) {
    ref?.child("users").setValue(["Fornavn": Fornavn.text!])
}

I have imported FirebaseDatabase and made a ref:

ref = Database.database().reference()

My rules are:

{
    "rules": {
        ".read": true,
        ".write": true
    }
}

Any ideas?

2

2 Answers

2
votes

Replace this Realtime Database Rules section in firebase

{
  "rules": {
    ".read": true,
    ".write": true,
    "users":{
        ".read": true,
        ".write": true,
    }
  } 
}

and Do not forget to click on publish button.

Note: This heppens because of using the wrong configuration file GoogleService-info.plist Please check DATABASE_URL,other data and update your GoogleService-info.plist

Reference:https://firebase.google.com/docs/database/security/

1
votes

Step 1. Go to Database. Step 2. Select Realtime Database from the dropdown. (This cost me 4 hours) Step 3. Change Rule

{  
    "rules": {
    ".read": true,
    ".write": true
   }
}

Follow this instruction