为什么我会看到“400(错误请求)"?登录 Firebase 身份验证失败时在我的开发者控制台中? [英] Why do I see a "400 (Bad Request)" in my developer console when sign-in to Firebase Authentication fails?

查看:30
本文介绍了为什么我会看到“400(错误请求)"?登录 Firebase 身份验证失败时在我的开发者控制台中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用方法 signInWithEmailAndPassword 在我的基于 Angular 的应用程序中验证用户,我编写了以下代码:

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);
            }      
      }
    });

当我使用有效的用户和密码运行此代码时,它运行良好,控制台中没有错误,但是当我设置无效用户时,它会在控制台中抛出错误请求,然后返回相应的错误,即用户不存在.所以看起来验证工作正常,但我想知道这个错误的请求意味着什么或者我在代码中遗漏了什么.这是错误的请求消息

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/客户端然后将其转换为带有您处理的 errorCodeerrorMessage 的错误.

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆