Firebase:用户未注册

时间:2016-06-06 15:42:04

标签: javascript firebase firebase-authentication

我在创建Firebase用户时遇到问题。虽然用户没有注册,但我通过HTML电子邮件和密码表单注册用户。我的控制台上没有显示任何错误,所以我不认为这是学校计算机的问题。以下是我的代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>register</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
</head>
<body>  
    <div class="form">
        <div id="error"></div>
        <form onsubmit="registerUser();">
            <label>Email:</label>
            <input type="text" name="email" id="email"><br>
            <label>Password:</label>
            <input type="password" name="pwd" id="password"><br>
            <input type="submit" value="Sign Up"><br>
        </form>
    </div>

    <script src="https://www.gstatic.com/firebasejs/3.0.3/firebase.js"></script>
    <script>
        function registerUser() {
            try {
                var config = {
                    databaseURL: 'https://apcs-4bfaa.firebaseapp.com/',
                    apiKey: 'AIzaSyD56uqnAm5xcfVttSD5NPEQHwn22ojWMhg'
                };
                firebase.initializeApp(config);

                // new 3.0 SDK method!
                var ref = firebase.database().ref();

                function registerUser() {
                    var email = document.getElementById("email").value;
                    var password = document.getElementById("password").value;
                    firebase.auth().createNewUserWithEmailAndPassword(email, password);
                }
            }
            catch (e) {
                alert(e);
            }
        }
    </script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

createNewUserWithEmailAndPassword是异步的。确保您返回false并且不会重定向您的页面,直到返回的promise被解决。