如何解决"Http2CallStream上缺少或权限不足"的问题;

人气:603 发布:2022-10-16 标签: android firebase google-cloud-functions

问题描述

我正在尝试使用nodejs从云功能更新Firestore文档,但出现错误

I'm trying to update firestore document from cloud function using nodejs, but getting error

错误日志:

Error: Missing or insufficient permissions.
at Http2CallStream.call.on (/srv/node_modules/@grpc/grpc- 
js/build/src/client.js:101:45)
at emitOne (events.js:121:20)
at Http2CallStream.emit (events.js:211:7)
at process.nextTick (/srv/node_modules/@grpc/grpc-js/build/src/call- 
stream.js:71:22)
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickDomainCallback (internal/process/next_tick.js:219:9)

我试图更改Cloud Firestore安全规则,但未成功

I tried to change the Cloud Firestore Security Rules, no success

推荐答案

此问题已通过以下方式解决:

The problem was solved this way:

从Firebase控制台下载密钥.

将下载的.json文件保存在路径"./your project path/functions"中.

Save the downloaded .json file in the path "./your project path/functions".

将此代码添加到index.js的顶部:

Add this code to the top of your index.js:

var serviceAccount = require("./[downloaded file name].json");

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://[your project id].firebaseio.com"
});

部署功能.

807