如果用户成功注册firebase for web app,如何获取返回消息?

时间:2017-05-15 06:38:57

标签: javascript firebase firebase-authentication

这是我的java脚本firebase代码

var username = $("#user_email").val();
var password = $("#user_password").val();
   firebase.auth().signInWithEmailAndPassword(username, password).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  console.log(error);
  // ...
});

2 个答案:

答案 0 :(得分:0)

仅返回错误代码/消息。如果成功,您可以使用以下功能继续进行。

firebase.auth().onAuthStateChanged(function(user){
  if (user) {
    // User is signed in.
  } else {
    // No user is signed in.
  }
});

答案 1 :(得分:0)

我有一个最好的方法来做到这一点

firebase.auth().signInWithEmailAndPassword(username, password).then(function(user) {
  // User Logged In.
  console.log(user);
  // ...
}).catch(function(error) {
  // An error happened.
    });