【问题标题】:Firebase webhook returning error when successfulFirebase webhook 成功时返回错误
【发布时间】:2020-03-15 22:29:16
【问题描述】:

我在 Firebase 上设置了一个 webhook,以创建一个用户,我通过我的 Angular 应用程序调用该用户,即使用户成功创建,它也会向我的应用程序返回错误。这是我第一次尝试这个,所以我对这些方法还是陌生的。

Firebase 功能:

export const signUpUser = functions.https.onRequest((request, response) => {
    cors(request, response, () => {
        const data = request.query;
        admin.auth().createUser({
            email:data.email,
            emailVerified:false,
            password:data.password,
            displayName:data.name,
            disabled:false
        }).then((user) => {
            response.status(200).send(`Successfully created user ${user.displayName}`);
        }).catch((err) => {
            response.status(400).send("ERROR: " + err)
        })
    });
});

Angular 应用功能:

import { HttpClient, HttpParams } from '@angular/common/http';

testAPI(){
    let params = new HttpParams()
    .set('email', 'tes2t@test.com')
    .set('name', 'Tester2')
    .set('password', 'test123')

    this.http.get('https:somefake.url/signUpUser', {params:params}).subscribe(data => {
        console.log(data)
    }, error => {
        console.log(error)
    })
 }

留言

如图所示,我的响应消息位于错误对象中,并且消息变量包含失败消息。

我不是 100% 确定您是如何发回回复的,因为我是新手,所以我也将不胜感激一般的帮助和提示。

【问题讨论】:

    标签: angular firebase api google-cloud-functions angular-httpclient


    【解决方案1】:

    好的,所以我发现了自己的问题,我的 webhook 正在返回类型 'text' 但预期的响应类型是 'json' 。

    所以在 Angular 应用程序功能中,我只是添加了一个额外的字段“responseType: 'text'”,所以它看起来像:

    {params:params, responseType:'text'}

    【讨论】:

      猜你喜欢
      • 2021-01-12
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 2018-11-13
      • 2019-03-20
      • 2021-01-17
      • 2011-11-24
      • 1970-01-01
      相关资源
      最近更新 更多