Error: Uncaught (in promise): Firebase already initialized
See original GitHub issueI’m running firebase.init() in the first major component that loads. This component checks if the user is logged in and redirects appropriately - all good till this point.
Now if I “back” out of the app (Android device used for testing), and try to launch the app again, I get the error “Error: Uncaught (in promise): Firebase already initialized”.
Is there a way to resolve this? Maybe by destroying the firebase instance when the user exits the app? Or check if firebase is initialized and reuse the existing instance?
Thanks!
My package.json
"nativescript-plugin-firebase": "^6.1.1",
"nativescript-angular": "6.0.0",
"nativescript-angular-cli": "0.1.9",
"tns-core-modules": "4.2.0-2018-06-29-01",
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
NativeScript Firebase already initialized - Stack Overflow
init error: Firebase already initialized". This happens when the changes don't trigger a whole application restart (ex. an html file). It ...
Read more >Fixing The 'FirebaseApp name already exists!' Error - Medium
Essentially, it is checking if there is already a firebase app running and only initializing if there isn't one. This works if you're...
Read more >Admin Authentication API Errors | Firebase - Google
The credential used to initialize the Admin SDK has insufficient permission to access the requested Authentication resource. Refer to Set up a Firebase...
Read more >error: the default firebase app already exists. this means you ...
error: the default firebase app already exists. this means you called initializeapp() more than once without providing an app name as the second...
Read more >[Solved] No Firebase App '[DEFAULT]' has been created Error
While using Firebase services in Flutter, you may get ʺNo Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()ʺ Error in Flutter.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mosesweb I think you @ the wrong person 😛
To shed a light into this issue, it does seem that firebase keeps running (and initialized) after all of angular dies. This IS an issue as it may not bind the new event listeners if you call them on init (your
this
WILL NOT point to the current instance).Turns out we never faced it before because I’ve always used the “addcallback” methods, like
addOnMessageReceivedCallback
, so we replace the callback before it’s called by firebase. Perhaps @EddyVerbruggen can point to the correct approach to handling this? I couldn’t find a way to “remove” the callbacks, or a way to check if firebase is initialized or not.It also seems like ngOnDestroy is not even called after the app is closed via back button, so the best approach is probably a check for when firebase is already initialized and a quick replacement of the callbacks.
Maybe using WeakRef may also work on determining if firebase should call the callbacks or store the events until they are rebound
Edit:
On a sidenote, nativescript-angular does not call ngOnDestroy when the app dies, but will soon (https://github.com/NativeScript/nativescript-angular/pull/1728) so we could remove the firebase callbacks when it’s destroyed and add them again when needed. Otherwise we might need to implement our own global handler which queues events for when angular is ready to receive them.
@edusperoni thanks for the links. I did this, seems to work great. Just have a property you set if you should init firebase.