Cloud Firestore 模拟器未运行,因此调用 Firestore 将影响生产

Nik*_*Nik 4 node.js firebase reactjs firebase-tools google-cloud-firestore

我正在学习 firebase 来与我的 React Web 应用程序集成。我试图为 GET 和 POST 请求编写函数,并使用我在 vscode 中的终端中获得的端点在邮递员上运行它们。\n现在我的代码与 firebase 部署完美配合,但在我尝试使用 firebase 服务时出现错误。另外,我不能简单地使用这些命令,我​​必须使用 sudo 运行它们,然后输入我的密码,只有这样我才能运行它们。\n下面是错误列表

\n\n
\n

Cloud Firestore 模拟器未运行,因此对 Firestore 的调用将影响生产。

\n\n

\xe2\x9a\xa0 请求外部网络资源!\n - URL: " http://169.254.169.254/computeMetadata/v1/instance "\n - 请小心,这可能是生产服务。

\n\n

\xe2\x9a\xa0 请求外部网络资源!\n - URL:“ http://metadata.google.internal./computeMetadata/v1/instance ”\n - 请小心,这可能是生产服务。

\n\n

错误:无法加载默认凭据。浏览至https://cloud.google.com/docs/authentication/getting-started了解更多信息。

\n\n
 at GoogleAuth.getApplicationDefaultAsync (/home/nikunj/socialape-functions/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:160:19)\n\n at processTicksAndRejections (internal/process/task_queues.js:97:5)\n\n at async GoogleAuth.getClient (/home/nikunj/socialape-functions/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:502:17)\n\n at async GrpcClient._getCredentials (/home/nikunj/socialape-functions/functions/node_modules/google-gax/build/src/grpc.js:92:24)\n\n at async GrpcClient.createStub (/home/nikunj/socialape-functions/functions/node_modules/google-gax/build/src/grpc.js:213:23)\n
Run Code Online (Sandbox Code Playgroud)\n\n

原因:错误

\n\n
 at WriteBatch.commit (/home/nikunj/socialape-functions/functions/node_modules/@google-cloud/firestore/build/src/write-batch.js:415:23)\n\n at DocumentReference.create (/home/nikunj/socialape-functions/functions/node_modules/@google-cloud/firestore/build/src/reference.js:283:14)\n at CollectionReference.add (/home/nikunj/socialape-functions/functions/node_modules/@google-cloud/firestore/build/src/reference.js:2011:28)\n at /home/nikunj/socialape-functions/functions/index.js:32:10\n at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:559:20\n at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:534:19\n at Generator.next (<anonymous>)\n at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:8:71\n at new Promise (<anonymous>)\n at __awaiter (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:4:12)\n
Run Code Online (Sandbox Code Playgroud)\n\n

i 函数:在约 1 秒内完成“createScream”

\n
\n

Nik*_*Nik 5

我实际上通过在 firebase 项目设置中使用服务帐户提供凭据解决了这个问题。我将我的初始化应用程序更改为

    var serviceAccount = require("path/to/serviceAccountKey.json");

    admin.initializeApp({
     credential: admin.credential.cert(serviceAccount),
     databaseURL: "https://socialape-6925b.firebaseio.com"
     });```
Run Code Online (Sandbox Code Playgroud)