首页 > 解决方案 > 使用 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);
});

谁能解释我为什么会收到错误以及如何解决问题?

非常感谢。

标签: firebasestripe-payments

解决方案


我解决了我自己的问题。密钥标记不正确,因此未正确加载。


推荐阅读