Firebase身份验证获取错误:signInWithEmailAndPassword失败:第一个参数“ email”必须为有效字符串

时间:2019-03-01 15:58:45

标签: firebase-authentication addeventlistener

HTML

 Email : <input type="email" id="txtEmail"><br>
    Password : <input type="password" id="txtPassword"><br>
    <button id="btnLogin">Log In</button>
    <button id="btnSignUp">Sign Up</button>

JS

 document.getElementById('btnLogin').addEventListener('click',e => {
          //get Email and Pass
          const email = document.getElementById('txtEmail');
          const pass = document.getElementById('txtPassword');
          const auth = firebase.auth();

          const promise = auth.signInWithEmailAndPassword(email,pass);
          promise.catch(e => console.log(e.message));
      });

出现以下错误:

  

第一个参数“ email”必须为有效的字符串。

1 个答案:

答案 0 :(得分:0)

将代码中的以下代码段更改为:

const email = document.getElementById('txtEmail').value;
const pass = document.getElementById('txtPassword').value;