I tried to split all my function in many files but I've a problem with firebase-admin initialization. I've my first file like this:
const functions = require('firebase-functions'); const admin = require('firebase-admin') admin.initializeApp(functions.config().firebase) const userHandler = require('./user') and second file user.js
const functions = require('firebase-functions') const admin = require('firebase-admin') ... exports.update = (req, res) => { admin.auth().verifyIdToken(req.body).catch(error => {console.log(error)} } All in a single file it works perfectly, in 2 separate file give me this error:
ReferenceError: ISTANCE_NAME is not defined I can't do a second initializeApp in a user.js because firebase throw an error:
Error: The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument. In most cases you only need to call initializeApp() once. But if you do want to initialize multiple apps, pass a second argument to initializeApp() to give each app a unique name.
How I can use the same istance of admin shared in 2 files? I've tried also to put the initializeApp function in another file and import it but not works, same error (ISTANCE_NAME is not defined)