#node.js #firebase #google-cloud-firestore #google-cloud-functions #plaid
#node.js #firebase #google-облако-firestore #google-cloud-функции #плед
Вопрос:
У меня возникли проблемы с локальным тестированием функций firebase. У меня есть некоторые критические ключи API, которые я хочу защитить. Поэтому для этого я использую functions.config()
.
При локальном запуске вашего сервера функций с firebase emulators:start
помощью или firebase emulators:start --only functions
он показывает мне ошибку, когда secret
значение равно нулю при использовании functions.config().plaid.secret
.
Раньше я 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 С моей стороны это все еще не решено.
Ответ №1:
Хорошо, решение состоит в том, чтобы фактически использовать то, что указано в документации. начиная с этого:
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, что абсолютно неправильно.