0

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

2 Answers 2

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)
0
0

if anyone interested in typescript version, the code needs to be updated with:

const config = JSON.parse(<string>process.env.FIREBASE_CONFIG))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.