1

This Is The Code I Plugged In To Add My User To Firebase Database With But I Have Received An Error IN My setvalue Linking To Firebase Database How Do I Fix This

[Firebase/Database][I-RDB038012] setValue: or removeValue: at /users/HqQpSf9FjUgKWrG1bb3UTdedwNP2/HqQpSf9FjUgKWrG1bb3UTdedwNP2 failed: permission_denied

Auth.auth().createUser(withEmail: EmailTextField.text!, password: PasswrdTextField.text!) { authResult, error in
           // [START_EXCLUDE]

             guard let user = authResult?.user, error == nil else {

               return
             }
    let ref = Database.database().reference()
    let UsersReference = ref.child("users").child(user.uid)
    // print(UsersReference.description()) : https://tvmassmedianetwork.firebaseio.com/
    let uid = user.uid
    let newUsersReference = UsersReference.child(uid)
    newUsersReference.setValue(["username": self.UsernameTextField.text!, "email": self.EmailTextField.text!])
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • By default reads/writes to the database from client-side SDKs are disabled these days. You'll want to modify the security rules of your database in the Firebase console to allow such writes, but using the first example in the answer I linked. I also recommend studying the Firebase documentation on [securing your database](https://firebase.google.com/docs/database/security). – Frank van Puffelen Nov 14 '19 at 14:35

1 Answers1

1

Change the permission rules in the firebase database console to the following:

// These rules give anyone, even people who are not users of your app,
// read and write access to your database
{
  "rules": {
    ".read": true,
    ".write": true
  }
}

During development, you can use the public rules in place of the default rules to set your files publicly readable and writable. This can be useful for prototyping, as you can get started without setting up Authentication. This level of access means anyone can read or write to your database. You should configure more secure rules before launching your app.

More info here:

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

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134