0
var config = {
  apiKey: "A**********************kBs",
  authDomain: "the**********.firebaseapp.com",
  databaseURL: "https://***********.firebaseio.com",
  projectId: "the-o***********nette",
  storageBucket: "the***********.appspot.com",
  messagingSenderId: "6***********6"
};

firebase.initializeApp(config);

$("#register").click(
  function() {

    var email=$("#regEmail").val();
    var password=$("#regPass").val();
    var fname=$("#regfName").val();
    var lname=$("#reglName").val();

    firebase.auth().createUserWithEmailAndPassword(email, password)
    .catch(function(error) {
      // Handle Errors here.
      var errorCode = error.code;
      var errorMessage = error.message;
      alert(errorMessage)
    });

    alert( "you have successfully registered");

    // Get a reference to the database service
    var database = firebase.database();
    var userId = firebase.auth().currentUser;


    firebase.database().ref('users/' + userId).set({
      fname: fname,
      lname: lname,
      email: email,
    })
    .catch(function(error) {
      var errormsg=error.message;
      console.log(errormsg);
    });

  }
);

The createuserwithemailandpassword is working properly. But I am not able to add anything into the database. No error log is reported. The var is mentioned in the HTML file. Let me know if anything else is needed. thanks!

1 Answer 1

1

You are passing the full user object instead of the uid. Please try this:

var userId = firebase.auth().currentUser.uid;
firebase.database().ref('users/' + userId).set();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.