Skip to content
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

Issue: FirebaseError: No Firebase App '[DEFAULT]' has been created #3

Open
palashshah110 opened this issue Jun 28, 2024 · 0 comments
Open

Comments

@palashshah110
Copy link
Owner

palashshah110 commented Jun 28, 2024

Description

I am encountering the following error when using the refine-firebase-adapter package in my project:

FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call initializeApp() first (app/no-app)

This error occurs even though I have called the initializeFirebase function before using any Firebase services.

Steps to Reproduce

  1. Install the refine-firebase-adapter package.
  2. Create a Firebase configuration object.
  3. Call the initializeFirebase function with the configuration object.
  4. Attempt to use auth and db services.

Example Code

Here is a simplified version of my code:
`import { initializeFirebase } from 'refine-firebase-adapter';

const firebaseConfig = {
apiKey: "apikey",
authDomain: "key",
projectId: "key",
storageBucket: "key",
messagingSenderId: "key",
appId: "key"
};

// Initialize Firebase
const { auth, db } = initializeFirebase(firebaseConfig);

// Attempt to use auth and db
console.log(auth, db);

Expected Behavior

I expect the Firebase app to be initialized, and the auth and db services to be available for use without throwing any errors.

Actual Behavior

The error FirebaseError: No Firebase App '[DEFAULT]' has been created - call initializeApp() first (app/no-app) is thrown, indicating that Firebase is not properly initialized.

Package Code

Here is the relevant part of the refine-firebase-adapter package code:

src/firebase/firebaseconfig.ts:`

`import { initializeApp, FirebaseApp } from 'firebase/app';
import { getAuth, Auth } from 'firebase/auth';
import { getFirestore, Firestore } from 'firebase/firestore';

let app: FirebaseApp | null = null;
let auth: Auth;
let db: Firestore;

const initializeFirebase = (firebaseConfig: any) => {
if (!app) {
app = initializeApp(firebaseConfig);
auth = getAuth(app);
db = getFirestore(app);
}
return { auth, db };
};

export { initializeFirebase, auth, db };
`
src/index.ts:

export { default as authprovider } from './authprovider/authprovider'; export { default as dataprovider } from './dataprovider/dataprovider'; export { initializeFirebase, auth, db } from './firebase/firebaseconfig';

Additional Context

I have ensured that initializeFirebase is called before any Firebase services are used.
The configuration object is correctly provided.
The issue persists even after re-publishing the package and reinstalling dependencies.

Environment

Node version: [e.g., 14.x]
npm version: [e.g., 6.x]
Package version: [e.g., 1.0.0]
Firebase version: [e.g., 9.6.1]
Any guidance or help to resolve this issue would be greatly appreciated. Thank you!

@palashshah110 palashshah110 pinned this issue Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant