javascript - Firebase signInWithEmailAndPassword not working as well
问题描述
I'm getting problems when try to login with an registered email in signInWithEmailAndPassword Firebase method in JavaScript. I know that the problem is with the fields required, but i don't know how to fix it. Here is my snipet
<form>
<input type="email" id="inputEmail" class="form-control" placeholder="Email address" autofocus="autofocus" required="required">
<input type="password" class="form-control" id="inputPassword" placeholder="Password">
<button class="btn btn-primary btn-block" id="btnLogin">Login</button>
</form>
<script>
$('#btnLogin').click(function(){
var email = $('#inputEmail').val();
var password = $('#inputPassword').val();
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode === 'auth/wrong-password') {
alert('Wrong password.');
} else {
alert(errorMessage);
}
console.log(error);
});
});
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
alert("User is signed in");
} else {
// No user is signed in.
alert("No user is signed in");
}
});
</script>
</body>
This was to be the original code that does not work (it gives me the message "No user is signed in"), but if I force a validation error (for example leave the fields empty and put the value directly in the variables), it gives seconds and returns the message "User is signed in"
var email = "a@a.com";
var password = "123456";
//var email = $('#inputEmail').val();
//var password = $('#inputPassword').val();
Another way I forced to give the error and it worked was putting an input hidden and required. In that case I returned an error in the console, but after a few seconds I received the message "User is signed in". The code of input:
<input type="text" class="form-control" id="inputHidden" required="required" hidden>
The error:
An invalid form control with name='' is not focusable.
ReferenceError: email is not defined
at Object.next (login.html:135)
at subscribe.ts:104
at subscribe.ts:225
解决方案
推荐阅读
- javascript - Node接口只是一个概念吗?元素接口和节点接口有什么区别?
- javascript - 在 Vue 中通过 AXIOS 发布请求总是返回 405 和 CORS 错误
- python - 多评分输入 RandomizedSearchCV
- flutter - showDialog 函数没有将父上下文传递给 Flutter 中的子代?是这样构思的吗?
- linux - Bash脚本无限while循环
- vba - VBA网页滚动
- javascript - 它显示未捕获的 referenceError :$ 未定义。到底是什么问题无法理解
- python - 如何使用 python-binance 获取订单的 orderId?
- javascript - 如何在javascript中检索文本中字符串第一个字符的索引?
- django - Windows Server 2012 上的 Django 应用程序 - HTTP 错误 500.0 - FastCGI 进程意外退出