我想通过Firebase提供用户身份验证,但是页面上的登录正在接受无效的输入


<script>
      function save_user()
      {
     const uid = document.getElementById('user_id');
            const userpwd = document.getElementById('user_pwd');
            const btnregister=document.getElementById('btn-action');
            //btnregister.addEventListener('click', e=>
            //{
            const email=uid.value;
            const pass=userpwd.value;
            firebase.auth().signInWithEmailAndPassword(email, pass).catch(function(error) {
    // Handle Errors here.
    var errorCode = error.code;
    console.log(error.Message);
});
firebase.auth().onAuthStateChanged(function(user) {
  if(user) {
    window.location='userpage.html'; 
  }
});
            }
    </script>
<link href="page2.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="bg">
  <img src="images/5.jpg" alt="">
</div>
<div class="loginbox">
<img src="images/logo.jpg" class="user"/>
<form action="" method="post">
<p>Email</p>
<input type="text" name="" placeholder="Enter Email" id="user_id"/>
<p>Password</p>
<input type="password" name="" placeholder="......" id="user_pwd"/>
</br>
</br>
</br>
<input type="button" name="" value="Sign In" id="btn-action" onclick="save_user();">
<a href="#">Forgot Password</a>
<a href="Register.html">Register</a>
</form>
</div>
</body>
</html>

我想通过firebase提供用户身份验证,但登录页面正在接受无效的输入。如果用户不存在Firebase Authentication中的用户?

如何打印错误消息。

您可以简单地使用html5输入正则表达式将电子邮件格式正确到输入:

<form action="" method="post">
<input id="emailAddress" type="email"pattern="[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,4}$/">
<input type="submit">
</form>

最新更新