firebase - 使用 Firebase 函数的条带化错误:错误:您没有提供 API 密钥。您需要在 Authorization 标头中提供您的 API 密钥
问题描述
我编写了一个 Firebase 函数,当使用 Firebase 身份验证创建新用户时调用该函数。然后它尝试创建一个 Stripe 客户,但我在 Firebase 日志中收到以下错误:
createStripeCustomer
Error: You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g. 'Authorization: Bearer YOUR_SECRET_KEY'). See https://stripe.com/docs/api#authentication for details, or we can help at https://support.stripe.com/. at IncomingMessage.<anonymous> (/workspace/node_modules/stripe/lib/StripeResource.js:174:21) at Object.onceWrapper (events.js:420:28) at IncomingMessage.emit (events.js:326:22) at IncomingMessage.EventEmitter.emit (domain.js:506:15) at endReadableNT (_stream_readable.js:1241:12) at processTicksAndRejections (internal/process/task_queues.js:84:21)
完整的功能如下图所示,并已部署到 Firebase。Stripe 密钥是从配置文件中加载的:
import * as functions from "firebase-functions";
import {stripe} from "../../config";
export const createStripeCustomer = functions.auth.user().onCreate(async (user) => {
const customer = await stripe.customers.create({
email: "paying.user@example.com",
source: "src_18eYalAHEMiOZZp1l9ZTjSU0",
});
console.log("customer_Id@ ", customer.id);
});
谁能解释我为什么会收到错误以及如何解决问题?
非常感谢。
解决方案
我解决了我自己的问题。密钥标记不正确,因此未正确加载。
推荐阅读
- jetty - 带有 Jersey 和嵌入式 Jetty 的 CrossOriginFilter
- android - 如果项目存在于数据库中,Android Firestore 更新字段值
- wordpress - 如何在 wordpress 发布后向 mailchimp 自动化发送电子邮件
- typescript - 将值传递到量角器中黄瓜的不同步骤
- javascript - Angular:你能提取文本响应类型的状态吗?
- javascript - 离线时此测验如何获得答案?
- java - 访问者模式中 List.of() 的使用
- jira - Jira:工单显示为已解决,分辨率设置为无
- node.js - 如何修复错误 [ERR_ASSERTION]:构造函数已存在!("inversify-restify-utils": "^3.4.0") 和 ("inversify-restify-utils": "^3.4.0")
- keras - 在 Keras 中,simpleRNN 后面是否总是需要一个密集层?