为什么我看到"400(错误请求)"在开发人员控制台中登录Firebase身份验证失败时? [英] Why do I see a "400 (Bad Request)" in my developer console when sign-in to Firebase Authentication fails?
问题描述
我正在使用signInWithEmailAndPassword方法在基于角度的应用程序中验证用户,我编写了以下代码:
I'm using the method signInWithEmailAndPassword to validate a user in my angular based application, I wrote this code:
firebase.auth().signInWithEmailAndPassword(email, password).then(
function(authData) {
//user was validated
console.log(authData);
},
function(error) {
if(error){
// Handle Errors
var errorCode = error.code;
var errorMessage = error.message;
// [START_EXCLUDE]
if (errorCode === 'auth/wrong-password') {
alert('Wrong password.');
} else {
alert(errorMessage);
}
}
});
当我使用有效的用户名和密码运行此代码时,它运行良好,在控制台中没有错误,但是当我设置无效的用户时,它将在控制台中引发Bad Request,然后返回相应的错误,即user不存在.因此,看来验证工作正常,但我想知道这个错误的请求意味着什么,或者我在代码中丢失了什么.这是错误的请求消息
When I run this code with a valid user and password it works well, no errors in the console, but when I set an invalid user it throws a Bad Request in the console, and then it returns the corresponding error which is user inexistent. So it seems the validation is working fine but I wonder what this bad request means or what I'm missing in the code. This is the bad request message
POST https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key = AIzaSyDDCVDWgy9LGYLWmMPQjPZ49RbDkWjWVTk 400(错误请求)firebase.js:107
POST https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=AIzaSyDDCVDWgy9LGYLWmMPQjPZ49RbDkWjWVTk 400 (Bad Request) firebase.js:107
预先感谢
推荐答案
此HTTP请求是Firebase身份验证如何验证用户凭据的方式.然后,SDK/客户端会用您处理的errorCode
和errorMessage
将其转换为错误.
This HTTP request is how Firebase Authentication verifies the user credentials. The SDK/client then turns it into the error with an errorCode
and errorMessage
that you handle.
如果您查看响应的正文,您会发现:
You can see that if you look in the body of the response:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "EMAIL_NOT_FOUND"
}
],
"code": 400,
"message": "EMAIL_NOT_FOUND"
}
}
这篇关于为什么我看到"400(错误请求)"在开发人员控制台中登录Firebase身份验证失败时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!