Luke Pighetti
Luke Pighetti

Reputation: 4841

Firebase Functions Typescript initializeAdmin() with specific uid

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

Upvotes: 0

Views: 739

Answers (2)

hatirlatici
hatirlatici

Reputation: 1695

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

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

Upvotes: 0

Doug Stevenson
Doug Stevenson

Reputation: 317948

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)

Upvotes: 1

Related Questions