【发布时间】:2021-08-27 21:55:29
【问题描述】:
我编写了一个 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);
});
谁能解释我收到错误的原因以及如何解决问题?
非常感谢。
【问题讨论】: