New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The default Firebase app already exists. This means you called initializeApp() more than once #1532
Comments
@tolotrasamuel I am not sure what causes this issue but I think it will be fixed as soon as this PR is released since we no longer call To be sure, could you run |
|
@samtstern It seems like the function is running twice that's why it throws the error
By the way I am using
And
|
@tolotrasamuel could you try replacing this:
With just this:
|
I already tried. Exact same error @samtstern
|
@tolotrasamuel we just released |
Yes, 7.2.0 works. I was a bug with 7.1.0 then
Thanks
Tolotra Samuel Randriakotonjanahary
https://tolotra.com
…On Wed, Jul 24, 2019 at 8:47 PM Sam Stern ***@***.***> wrote:
@tolotrasamuel <https://github.com/tolotrasamuel> we just released
firebase-tools version 7.2.0 about 5 minutes ago. That contains the fix
for #1479 <#1479> that I
was mentioning. Could you upgrade (npm install -g ***@***.***)
and see if you still have this issue? If so please provide debug logs
again. Thanks for your help and patience!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1532?email_source=notifications&email_token=AG7AJXYJ2WLPZW444LLCZI3QBCBQHA5CNFSM4IFPWD6KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2W523Y#issuecomment-514710895>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AG7AJX757XRQWNAYM6TWB7LQBCBQHANCNFSM4IFPWD6A>
.
|
@tolotrasamuel thanks! |
Hi. Using 9.1.0 version and still the same |
same here, is there any solution yet? |
Tente: |
here's what I'm doing: const admin = require('firebase-admin');
if (admin.apps.length === 0) {
admin.initializeApp();
} |
@markgoho that's the slam dunk right there ;D thank you. |
@markgoho Thank you so much |
Doesn't work for me unfortunately @markgoho EDIT: I thought that was the problem, but actually I'm getting 1 app on the admin.apps array and that's why it doesn't enter the if. // Init and signIn on Firebase
console.log(`AAAAAAAAAAAAAAAAAAAA: ${admin.apps.length.toString()}`);
if (admin.apps.length === 0) {
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://****.firebaseio.com',
});
} EDIT 2: Nevermind, I was initializing the app inside the |
I guess It depends on how you are using the AdminSDK, what works for me (as I'm using as modules) is this. const { initializeApp } = require('firebase-admin/app')
const { getAuth } = require('firebase-admin/auth')
if (!app) {
const app = initializeApp()
const auth = getAuth(app)
module.exports = { auth }
} |
I have the same issue. When I deploy
I am using
I have tried this and I still get the same error
EDIT: Found the issue it was caused by third-party imports
|
If your app is already created, you may need to delete it somewhere in your apps lifecycle before creating another. Firebase apps have global namespace. This will be specific to your setup: For example in NestJS async onModuleInit() {
const options = this.config.get<AppOptions>(FirebaseService.CONFIG_KEY);
this.app = initializeApp(options);
}
async onModuleDestroy() {
if (this.app) {
await deleteApp(this.app);
}
} |
Checking the let app: ReturnType<typeof initializeApp>
function getFireStore() {
if (!app && !admin.apps.length) {
try {
app = initializeApp({
credential: admin.credential.cert(configDecoded)
})
} catch (error) {
console.error(error)
}
}
return admin.firestore()
}
const firestore = getFireStore()
export const tokensCollection = firestore.collection('tokens') |
[REQUIRED] Environment info
firebase-tools: 7.1.0
Platform: Windows 10
[REQUIRED] Test case
[REQUIRED] Steps to reproduce
Run
firebase emulators:start --only functions
visit the url of the function on your browser
[REQUIRED] Expected behavior
initializeApp should be called only once
[REQUIRED] Actual behavior
initializeApp is called everytime the url is called
The text was updated successfully, but these errors were encountered: