【问题标题】:getting error in creating the use user in the firebase?在 Firebase 中创建用户时出错?
【发布时间】:2017-11-07 05:37:55
【问题描述】:
    var rootRef = firebase.database().ref();
    var vasu = rootRef("https://<my app>.firebaseio.com")
rootRef.createUser({
  email    : "swamy1234@gmail.com",
  password : "swamy1234"
}, function(error, userData) {
  if (error) {
    console.log("Error creating user:", error);
  } else {
    console.log("Successfully created user account with uid:", userData.uid);
  }
});

在浏览器中运行时出现错误

error : Uncaught TypeError: rootRef is not a function
    at (index):771
(anonymous) @ (index):771

请给我一个正确的代码

【问题讨论】:

标签: javascript firebase firebase-realtime-database firebase-authentication


【解决方案1】:

使用以下代码使用电子邮件地址和密码登录用户

firebase.auth().createUserWithEmailAndPassword({
      email    : "swamy1234@gmail.com",
      password : "swamy1234"
    }).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // ...
});

【讨论】:

    【解决方案2】:
    var rootRef = firebase.database().ref();
    let newTransactionRef = rootRef.child('user').push()
    // here user is your database ref in which you may want to insert a new user data
    newTransactionRef.set('user').push({
          email    : "swamy1234@gmail.com",
          password : "swamy1234"
        }).then(function (userData) {
        // successfully created
        console.log("Successfully created user account with uid:", userData.uid);
    }).catch(function(error){
      //error
      console.log("Error creating user:", error);
    })
    

    【讨论】:

    • 我们如何在 fire base 中管理用户帐户,例如重置密码
    • 所以你需要密码重置代码,对吧?您是使用 firebase-ui 进行身份验证还是自定义身份验证?
    • 是的,我知道如何将新用户添加到火力基地的代码
    猜你喜欢
    • 2021-01-15
    • 2016-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-31
    • 2011-03-28
    • 2018-08-19
    相关资源
    最近更新 更多