Firebase Functions Typescript initializeAdmin() with specific uid

安稳与你 提交于 2019-12-13 03:26:17

问题


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

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" }
});

回答1:


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)


来源:https://stackoverflow.com/questions/52959389/firebase-functions-typescript-initializeadmin-with-specific-uid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!