创建新用户firebase

时间:2016-04-02 12:51:54

标签: javascript firebase

我仍然在学习Javascript并尝试在给定两个输入文本字段的情况下创建一个新用户帐户。我一直收到以下错误。

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

但我很难过。我如何将.val()返回转换为字符串文字? 创建帐户的代码:

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);
      }
    });
}

2 个答案:

答案 0 :(得分:1)

你只是错过了一个逗号。在email : $("#email").val()

之后加一个

答案 1 :(得分:0)

//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@emails.com";
 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`
        });
    }