Firebase Functions Typescript initializeAdmin() with specific uid
Asked Answered
I

2

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" }
});
Isiahisiahi answered 24/10, 2018 at 0:10 Comment(0)
L
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)
Llamas answered 24/10, 2018 at 0:32 Comment(0)
C
0

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

const config = JSON.parse(<string>process.env.FIREBASE_CONFIG))
Campus answered 1/1, 2020 at 17:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.