【发布时间】: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