【问题标题】:Returning from data from firebase cloud callable function using plaid使用格子从firebase云可调用函数的数据返回
【发布时间】:2019-11-25 20:04:13
【问题描述】:

您好,我正在调用 firebase 可调用函数,但它始终返回 null。我不确定我到底做错了什么。我正在尝试使用 plaid 交换我的令牌并获取访问令牌,但这里是我使用 https://plaid.com/docs/https://firebase.google.com/docs/functions/callable 作为编写代码的参考。任何建议将不胜感激

exchange token 

const exchange_token = (data, context) => {

    const public_token = data.public_token;

    if (!context.auth) {
        throw new functions.https.HttpsError('failed-precondition', 'The function must be called ' +
            'while authenticated.');
    }
    return Plaid.client.exchangePublicToken(public_token, (error, tokenResponse) => {
        if (error !== null) {
            var msg = 'Could not exchange public_token!';
            return {
                status: 400,
                error: msg
            }
        }
        ACCESS_TOKEN = tokenResponse.access_token;
        ITEM_ID = tokenResponse.item_id;
        console.log("Access token: " + ACCESS_TOKEN + " Item Id: " + ITEM_ID);
        return {
            access_token: ACCESS_TOKEN,
            item_id: ITEM_ID,
            error: false
        };
    });
}

and my front end service 

exchangeToken(public_token: string){
    const exchangeToken$ = this.fireFunctions.httpsCallable("exchangeToken");
    return exchangeToken$({public_token: public_token});
  }
  
  and then my component 
  
   this.bankService.exchangeToken(event.token).subscribe(
      value => this.processToken(value),
      error => this.handleError(),
      () => this.finished = true)

【问题讨论】:

  • 听起来是时候添加一些调试日志来找出究竟是什么没有按照您的预期工作。
  • @DougStevenson 我可以看到 ACCESS_TOKEN 存在于该函数中,并且我的控制台日志将其打印出来。但不知何故,它没有得到回报。我要退回这个并以正确的方式消费它吗?
  • 看起来格子兑换令牌函数返回void。 @DougStevenson 你对如何处理这种情况有什么建议吗?我需要向我的客户退还一些东西

标签: firebase google-cloud-functions plaid


【解决方案1】:

你好朋友我想通了,解决方案是将格子请求包装在一个承诺中,然后像这样返回那个承诺

function exhangeToken(resolve, reject ){
    Plaid.client.exchangePublicToken(public_token, (error, tokenResponse) => {
       if (error !== null) {
            var msg = 'Could not exchange public_token!';
            reject( {
                status: 400,
                message: msg
            })
        }
        ACCESS_TOKEN = tokenResponse.access_token;
        ITEM_ID = tokenResponse.item_id;
        console.log("Access token: " + ACCESS_TOKEN + " Item Id: " + ITEM_ID);
        resolve( {
            status: 200,
            message: "Token exchange success"
        });
    });
}
return new Promise(exhangeToken);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-18
    • 2021-09-13
    • 2020-04-18
    • 2021-08-29
    • 2021-12-06
    • 2020-05-17
    相关资源
    最近更新 更多