Turtle
Turtle

Reputation: 1389

Creating new user firebase

I am still learning Javascript and trying to create a new user account given two input text fields. I keep getting the following error.

'Unexpected identifier 'password'. Expected '}' to end a object literal.

but am quite stumped. How would I convert the .val() returns into a string literal? Code for creating account:

function create_user() {
  var myFirebaseRef = new Firebase("https://sweltering-heat-6293.firebaseio.com/");
  myFirebaseRef.createUser({

    email    : $("#email").val(),
    password : $("#pass1").val()
    }, function(error, userData) {
      if (error) {
        console.log("Error creating user:", error);
      } else {
        console.log("Successfully created user account with uid:", userData.uid);
      }
    });
}

Upvotes: 0

Views: 684

Answers (2)

Israelmikan
Israelmikan

Reputation: 1

//step one make an auth to your firebase datatabse as documented and on the developer console of firebase..

//two. create auser in authentication side of the fire base console...  here //https://console.firebase.google.com
//add these codes

//the create_user() function is called after asuccessfully authentication
//its working for me..

var messageListRef = new Firebase("https://sweltering-heat-6293.firebaseio.com/");

    messageListRef.authWithPassword({
      email    :"yourfirebaseemail",
      password : "yourpassword"
    }, function(error, authData) {
      if (error) {
        switch (error.code) {
          case "INVALID_EMAIL":
            console.log("The specified user account email is invalid.");
            break;
          case "INVALID_PASSWORD": 
            console.log("The specified user account password is incorrect.");
            break;
          case "INVALID_USER":
            console.log("The specified user account does not exist.");
            break;
          default:
            console.log("Error logging user in:", error);
        }
      } else {
        console.log("Authenticated successfully with payload:", authData);
        console.log("Successfully Autheticated");

 //call your function function
        create_user();



      }
    });   

//storing values in variables or use document.getElementByid 

 var email="[email protected]";
 var pass="pass";


    function create_user() {
      var messageListRef = new Firebase("https://sweltering-heat-6293.firebaseio.com/");
      messageListRef.createUser({
        email    : email,
        password : pass
        }, function(error, userData) {
          if (error) {
            alert("Try Again Error creating user or User with Same E-mail Exists",error);

          } else {
            alert("User Successfully created user accoount",email);
          }`enter code here`
        });
    }

Upvotes: 0

Rando Hinn
Rando Hinn

Reputation: 1322

You're simply missing a comma. Put one after email : $("#email").val()

Upvotes: 1

Related Questions