react-gatsby-firebase-authentication icon indicating copy to clipboard operation
react-gatsby-firebase-authentication copied to clipboard

Firebase App named '[DEFAULT]' already exists (app/duplicate-app).

Open arhoy opened this issue 4 years ago • 4 comments

HI, I have done the steps below but run into the following error when I try to sign in or register.

Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app).
▶ 2 stack frames were collapsed.
new Firebase
C:/Users/arhoy/OneDrive/Desktop/web-development/playground/gatsby/react-gatsby-firebase-authentication/src/components/Firebase/firebase.js:76
  73 |            }
  74 | 
  75 |            // merge auth and db user
> 76 |            authUser = {
  77 |              uid: authUser.uid,
  78 |              email: authUser.email,
  79 |              emailVerified: authUser.emailVerified,
View compiled
getFirebase
C:/Users/arhoy/OneDrive/Desktop/web-development/playground/gatsby/react-gatsby-firebase-authentication/src/components/Firebase/firebase.js:104
  101 |   messages = () => this.db.ref('messages');
  102 | }
  103 | 
> 104 | let firebase;
  105 | 
  106 | function getFirebase(app, auth, database) {
  107 |   if (!firebase) {
View compiled
(anonymous function)
C:/Users/arhoy/OneDrive/Desktop/web-development/playground/gatsby/react-gatsby-firebase-authentication/src/components/layout.js:1
> 1 | import React, { Component, Fragment } from 'react';
  2 | 
  3 | import Navigation from './Navigation';
  4 | import getFirebase, { FirebaseContext } from './Firebase';

I am not sure what I am doing wrong, I have set up my ENV variables from Firebase and all that.

Thank you

arhoy avatar Oct 02 '19 08:10 arhoy

@arhoy Did you find a solution ? I am facing the same issue.

smrutiparida avatar Oct 17 '19 10:10 smrutiparida

I had the same problem.

I created two files with the firebase credentials for prod/dev

  • .env.development
  • .env.production

I run gatsby develop and the app crashed with the previous error.

If you open the gatsby-config file you will see that it has this code in it

require("dotenv").config({
  path: `.env.${process.env.NODE_ENV}`,
})

That means that you have to pass a NODE_ENV before the gatsby develop command like that:

NODE_ENV=development gatsby develop (for development) NODE_ENV=production gatsby develop (for production)

In this way, it takes the NODE_ENV variable that you pass and it uses the correct env variables from .env.* files.

I believe that you can close the issue or maybe we can update the documentation accordingly to make it more clear?

gkartalis avatar Nov 13 '19 13:11 gkartalis

It works on-the-shelf if you put the credentials in .env

guhur avatar Jun 14 '20 15:06 guhur

I am experiencing the same problem with Firebase and Gatsby, not just this package. I would guess it has something to do with versioning.

marharyta avatar Jul 15 '20 07:07 marharyta