Skip to content

Migration Problem with the new process.env.FIREBASE_CONFIG #216

@ahaverty

Description

@ahaverty

Version info

"firebase-admin": "5.11.0",
"firebase-functions": "1.0.0",
"firebase-tools": "3.18.0",

Test case

I've migrated from functions beta to v1, but I'm having issues initializing firebase-admin since migrating.
My setup was a main index.ts which called admin.initializeApp(functions.config().firebase); at the top of my index.ts and then exports each firebase function below.
Since the change from admin.initializeApp(functions.config().firebase); to the new admin.initializeApp(), I've been receiving the error:

Error: Can't determine Firebase Database URL.
    at FirebaseDatabaseError.Error (native)
    at FirebaseDatabaseError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:39:28)
    at new FirebaseDatabaseError (/user_code/node_modules/firebase-admin/lib/utils/error.js:190:23)
    at DatabaseService.ensureUrl (/user_code/node_modules/firebase-admin/lib/database/database.js:75:15)
    at DatabaseService.getDatabase (/user_code/node_modules/firebase-admin/lib/database/database.js:52:26)
    at FirebaseApp.database (/user_code/node_modules/firebase-admin/lib/firebase-app.js:235:24)

I've determined that even attempting to console.log(process.env.FIREBASE_CONFIG) from the top of my index.ts prints undefined. However, printing the above from within each function export will print the config and allow me to initialize with admin.initializeApp().

It looks like I can workaround the change by adding admin.initializeApp() within each of my function exports, but I'd like to understand what's really going on. It's as if process.env.FIREBASE_CONFIG isn't set until each function is exported, whereas the beta version firebase.config().firebase was available instantly.
Is it recommended to initializeApp within each function?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions