为什么我会看到“400(错误请求)"?登录 Firebase 身份验证失败时在我的开发者控制台中?

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

问题描述

限时送ChatGPT账号..

我正在使用方法 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/identitytoolkit/v3/relyingparty/verifyPassword?key=AIzaSyDDCVDWgy9LGYLWmMPQjPZ49RbDkWjWVTk 400(错误请求)firebase.js:107

POST https://www.googleapis/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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-22 11:08:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1023507.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我会   控制台   开发者   身份验证   错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!