在Firebase数据库中注册新用户

时间:2017-02-01 18:21:53

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

这是我用来将用户注册到Firebase数据库的功能。一次又一次,else部分正在执行(即未创建用户)。我可以有替代代码吗?

function registerUser(email, password){
    firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {

        var user = firebase.auth().currentUser;
        if (user) {
            // User is created if will be automatically signed in
            console.log('created and signed in');
        } else {
            // No user created hence not signed in.
            console.log("failed");
        }
    });
}

1 个答案:

答案 0 :(得分:0)

    firebase.auth().createUserWithEmailAndPassword('email@gmail.com', 'password')
            .then(function (firebaseUser) {
                console.log(firebaseUser.user);
            })
            .catch(function (error) {
                console.log(error);
            });