node.js - Firebase本地使用配置变量不起作用-: Missing Plaid “Secret” 错误

标签 node.js firebase google-cloud-firestore google-cloud-functions plaid

我在本地测试Firebase功能时遇到问题。
我有一些要保护的关键api key 。因此,我使用functions.config()
当使用firebase emulators:startfirebase emulators:start --only functions在本地启动函数服务器时,当使用secretfunctions.config().plaid.secret值为null时,它向我显示错误。
我使用firebase functions:config:get > .runtimeconfig.json将配置带到本地。我在functions文件夹中运行了它。.runtimeconfig.json文件如下所示:

{
  "plaid": {
    "secret": "blabla",
    "clientid": "blabla"
  }
}
我的index.js如下所示:
// Using Express
const express = require('express');
const app = express();
app.use(express.json());

// Cloud Functions
const functions = require("firebase-functions");

// Cloud Firestore
const admin = require("firebase-admin");
admin.initializeApp();
const database = admin.firestore();

// Plaid
const plaid = require("plaid");
const plaidClient = new plaid.Client({
    clientID: functions.config().plaid.clientid,
    secret: functions.config().plaid.secret,
    env: plaid.environments.development,
});

// Firestore Refs
const usersRef = database.collection("users");

// Token Management
// Create Token
app.post('/get_link_token', async (request, response) => {
    try {
        const clientUserId = "SomeUserID";
        // Create the link_token with all of your configurations
        const tokenResponse = await plaidClient.createLinkToken({
            user: {
                client_user_id: clientUserId,
            },
            client_name: 'someproject',
            products: ['auth', 'transactions'],
            country_codes: ['US'],
            language: 'en',
        });
        response.on({ link_token: tokenResponse.link_token });
    } catch (e) {
        // Display error on client
        return response.send({ error: e.message });
    }
});
我的错误如下:
⚠  functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
⚠  Error: Missing Plaid "secret"
    at new Client (/Users/somedude/Work/someproject/functions/node_modules/plaid/lib/PlaidClient.js:17:11)
    at Object.<anonymous> (/Users/somedude/Work/someproject/functions/index.js:18:21)
    at Module._compile (node:internal/modules/cjs/loader:1083:30)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10)
    at Module.load (node:internal/modules/cjs/loader:948:32)
    at Function.Module._load (node:internal/modules/cjs/loader:789:14)
    at Module.require (node:internal/modules/cjs/loader:972:19)
    at require (node:internal/modules/cjs/helpers:88:18)
    at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:699:33
    at Generator.next (<anonymous>)
    at fulfilled (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:5:58)
    at processTicksAndRejections (node:internal/process/task_queues:93:5)
⚠  We were unable to load your functions code. (see above)

你知道我在做什么错吗?
提前致谢!
编辑:您在这里还有更多上下文https://github.com/plaid/plaid-node/issues/345
仍然无法解决我的问题。

最佳答案

好的,解决方案是实际使用文档中所述的内容。
截至此:

const plaidClient = new plaid.Client({
    clientID: functions.config().plaid.clientid,
    secret: functions.config().plaid.secret,
    env: plaid.environments.development,
});
并且确保至少使用版本7.0.0。
由于某些原因,在使用npm添加软件包时,它正在安装2.1.0,这绝对是不正确的。

关于node.js - Firebase本地使用配置变量不起作用-: Missing Plaid “Secret” 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64830018/

相关文章:

ios - 如何在 Xcode 中更改 $(PRODUCT_BUNDLE_IDENTIFIER)?

java - 如何与 Firestore 交互以减少客户端的 RAM 消耗?

java - 使用 Firestore RecyclerView 加载数据导致应用崩溃

javascript - EJS 和 jquery 不加载 javascript 引用

javascript - 如何使用 NodeJS 读取(文本)文件

node.js - 与 Node 的请求库一起使用 & 同步

javascript - Firestore 按日期查询

node.js - 将文件/文件夹复制到Electron Dist文件夹

android - 使用 Firebase 登录 Android - statusCode DEVELOPER_ERROR

list - 在 firestore 集合中保存从 JSON URL 获取的列表