Firebase函数类型脚本带有特定uid的initializeAdmin() [英] Firebase Functions Typescript initializeAdmin() with specific uid
问题描述
我已经找到了使用唯一UID初始化firebase函数的这种方法的参考,目的是用数据库规则来限制它,但是我不断收到错误消息
Error: Can't determine Firebase Database URL
I have found reference to this method of initializing firebase functions with a unique UID for the purpose of constraining it with database rules, but I keep getting the error
Error: Can't determine Firebase Database URL
我意识到我可以从环境变量中检索DatabaseURL,但是在此之前,我想知道自己是否做错了,因为我所看到的示例不必针对Firebase Functions进行操作.
I realize that I can retrieve the DatabaseURL from environment variables, but before I do that, I want to know if I'm doing something wrong because the examples I have seen have not had to do that for Firebase Functions.
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
admin.initializeApp({
...functions.config().firebase,
databaseAuthVariableOverride: { uid: "functions" }
});
推荐答案
functions.config().firebase
已弃用.相反,您可以改用process.env.FIREBASE_CONFIG
的内容.像这样(未经测试):
functions.config().firebase
is deprecated. Instead, you can build upon the contents of process.env.FIREBASE_CONFIG
instead. Something like this (untested):
const config = JSON.parse(process.env.FIREBASE_CONFIG)
config.databaseAuthVariableOverride = { uid: "uid" }
admin.initializeApp(config)
这篇关于Firebase函数类型脚本带有特定uid的initializeAdmin()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!