firebaseapperror: failed to parse private key: error: invalid pem formatted message当我将 Nodejs 应用程序推送到 Heroku 时,出现此错误。
我的环境变量都是这样设置的
# .env file
project_id=project_id
private_key='-----BEGIN PRIVATE KEY----- ... ------END PRIVATE KEY-----\n'
client_email=client_email
Run Code Online (Sandbox Code Playgroud)
并像这样访问它们:
export const sa = {
privateKey: process.env.private_key,
projectId: process.env.project_id,
clientEmail: process.env.client_email
};
Run Code Online (Sandbox Code Playgroud)
在我的本地一切工作正常,但在生产(heroku)我得到了上面提到的错误。私钥是一个多行环境变量,无法解析。
请问我该如何解决这个问题?
parsing environment-variables multiline node.js firebase-admin
在我的 firebase 云功能中,我已将 firebase-admin 升级到版本 11.0.0(从 9.12.0),并将引擎从 12 升级到 16。之后,当我在模拟器中运行代码时,admin.firestore.FieldValue 未定义。
当我部署代码时,它可以正常工作。
我喜欢在模拟器中测试。我可以做些什么来使其在模拟器中工作吗?
我的代码:
import * as admin from 'firebase-admin';
// Remove user permissions
await firestore.doc(`/${projectsPath}/${projectKey}`).update({
roUids: admin.firestore.FieldValue.arrayRemove(uidOfUserToDelete),
rwUids: admin.firestore.FieldValue.arrayRemove(uidOfUserToDelete),
});
Run Code Online (Sandbox Code Playgroud)
我的package.json:
{
"name": "functions",
"scripts": {
"lint": "eslint --ext .js,.ts .",
"build": "tsc",
"watch": "tsc --watch",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
},
"main": "lib/src/index.js",
"dependencies": {
"@sendgrid/mail": "^7.7.0",
"api2pdf": "^1.1.1",
"axios": "^0.19.2",
"firebase-admin": "^11.0.0",
"firebase-functions": "^3.22.0",
"firebase-tools": "^11.2.0",
"googleapis": "^104.0.0",
"lodash": "^4.17.21",
"mailchimp-api-v3": "^1.13.1",
"md5": "^2.2.1", …Run Code Online (Sandbox Code Playgroud) firebase firebase-tools firebase-admin google-cloud-firestore
我用以下方式设置我的云功能firebase-admin:
const admin = require('firebase-admin');
const fn = require('firebase-functions');
admin.initializeApp(fn.config().firebase);
Run Code Online (Sandbox Code Playgroud)
但是,我在写入数据库时获得了许可.奇怪的是它只发生在某些集合中,而不是发生在所有集合中.有些是作品,有些则不然.
我的理解admin.initializeApp(fn.config().firebase);是,这将允许我的云功能对数据库具有绝对的权力,无论如何security rules.
这是错误:
编辑
我写这样的数据.
exports.foo = fn.database.ref('some-path').onWrite(e => {
// some handling
const ref = e.data.ref;
return ref.child('bar').set('some-data').then( // ).catch( // );
})
Run Code Online (Sandbox Code Playgroud) 我正在学习firebase云功能.我有一个看起来像这样的功能:
exports.gameLoopBeing = functions.database.ref('/tables/{pushId}/gamestarted')
.onWrite(event => {
//I want to retrieve the pushID
console.log(event.data.pushID);
});
Run Code Online (Sandbox Code Playgroud)
event.data.pushID显然不起作用.如何检索pushID?我查看了文档但找不到任何内容.
对于那些不知道pushId的人.此函数侦听/ table内元素内所做的每个更改.例如:
我试图创建一个JSON对象并将其发送到Firebase Databaseusing python,但是当我这样做时,我得到:
TypeError: Object of type 'Tag' is not JSON serializable
这是我的代码:
data = {'address': address,
'name': name
}
print(type(data))
sent = json.dumps(data)
result = firebase.post("/tHouse/houseTest", sent)
Run Code Online (Sandbox Code Playgroud)
这是有问题的,json.dumps(data)因为此处指出了错误。print(type(data))虽然运行返回<class 'dict'>。
另外,name与address预先设定
python json firebase firebase-realtime-database firebase-admin
我有一个提供简单消息服务的网站.个人可以支付服务费用,或者企业可以支付每月订阅费用,然后免费添加他们的客户/用户.当企业添加客户端/用户电子邮件时,会触发下面的功能.我正在使用firebase函数和createUser在我的服务器上创建用户(更少).但是,有时企业会尝试注册用户并且该用户已经存在.在这种情况下,我想向用户发送提醒电子邮件.
我的代码工作正常,但在我的catch /错误中有一个链条感觉很时髦.是否有其他方法可以检测电子邮件是否已在Firebase帐户中注册,该帐户不会引发错误?
exports.newUserRegisteredByBusiness = functions.database.ref('users/{uid}/users/invited/{shortEmail}').onWrite( (data, context) => {
//don't run function if data is null
if (!data.after.val()){
console.log('SKIP: newUserRegisteredByBusiness null so skipping')
return null
} else {
let businessUID = context.params.uid
let email = data.after.val()
let shortEmail = context.params.shortEmail
let password // = something I randomly generate
return admin.auth().createUser({ email: email, password: password}).then( (user)=> {
//write new user data
let updates = {}
let userData // = stuff I need for service to run
updates['users/' + user.uid ] …Run Code Online (Sandbox Code Playgroud) 是否可以使用包含where子句的firebase cloud函数设置值?
例如
admin.firebase.firestore().collection('Accounts').where("imagePathName", '==', docNamed).set({
original: 'trial'
});
Run Code Online (Sandbox Code Playgroud)
这给我一个错误。
我正在创建一个网站,企业可以免费向其客户/用户提供我的服务.对于企业添加用户(在其企业帐户下),企业登录并输入其客户/用户电子邮件之一.然后,我将客户端/用户电子邮件发送到firebase功能并以编程方式创建帐户.
我想向这位新用户发送一封电子邮件,上面写着"创建帐户:重置密码"等等,我可以在浏览器上使用sendPasswordResetEmail执行此操作,但此功能在Firebase functions/admin上不可用.
最好的选择我可以想到它为每个新用户随机生成一个密码(即 - 'ef53gs'),并在欢迎电子邮件中分享新密码,但我认为如果欢迎电子邮件包括一个,那将是一个更好的体验链接到(重新)设置密码.
任何想法如何使像sendPasswordResetEmail这样的东西适用于firebase函数?
firebase firebase-authentication google-cloud-functions firebase-admin
我正在尝试使用包含500多个文档的集合中timestamp的Firestoreadmin时间戳更新字段。
const batch = db.batch();
const serverTimestamp = admin.firestore.FieldValue.serverTimestamp();
db
.collection('My Collection')
.get()
.then((docs) => {
serverTimestamp,
}, {
merge: true,
})
.then(() => res.send('All docs updated'))
.catch(console.error);
Run Code Online (Sandbox Code Playgroud)
这引发一个错误
{ Error: 3 INVALID_ARGUMENT: cannot write more than 500 entities in a single call
at Object.exports.createStatusError (C:\Users\Growthfile\Desktop\cf-test\functions\node_modules\grpc\src\common.js:87:15)
at Object.onReceiveStatus (C:\Users\Growthfile\Desktop\cf-test\functions\node_modules\grpc\src\client_interceptors.js:1188:28)
at InterceptingListener._callNext (C:\Users\Growthfile\Desktop\cf-test\functions\node_modules\grpc\src\client_interceptors.js:564:42)
at InterceptingListener.onReceiveStatus (C:\Users\Growthfile\Desktop\cf-test\functions\node_modules\grpc\src\client_interceptors.js:614:8)
at callback (C:\Users\Growthfile\Desktop\cf-test\functions\node_modules\grpc\src\client_interceptors.js:841:24)
code: 3,
metadata: Metadata { _internal_repr: {} },
details: 'cannot write more than 500 entities in a single …Run Code Online (Sandbox Code Playgroud) 我的本地功能可以在上正常运行
firebase serve --only functions
Run Code Online (Sandbox Code Playgroud)
但是一旦将其部署到云中,我就无法使用邮递员向其发出相同的get请求。我在stackdriver上收到以下错误:
Unexpected token u in JSON at position 0 at JSON.parse,我的请求返回以下内容:400. That’s an error.Your client has issued a malformed or illegal request. That’s all we know.
我在本地和Firebase中发送的数据是带有以下内容GET的类型的请求application/json:
{
"data": {
"Celebrity_A": "Brad Pitt",
"Celebrity_B": "Angelina Jolie"
}
}
与本地相比,firebase功能对远程有什么要求?
下面是我的功能开始:
// Main index.ts
exports.funct = functions.https.onRequest(functexp)
// functexp file
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import * as _request from 'request';
const serviceAccount …Run Code Online (Sandbox Code Playgroud) firebase-admin ×10
firebase ×8
node.js ×2
javascript ×1
json ×1
multiline ×1
parsing ×1
promise ×1
python ×1