firebase / firebase/firebase-js-sdk
onAuthStateChanged hangs on startup at PersistenceManager.create step
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 37
Description
### Operating System
Windows
### Environment (if applicable)
Chrome 128
### Firebase SDK Version
10.11.0
### Firebase SDK Product(s)
Auth
### Project Tooling
MV3 Chrome extension service worker built using webpack
### Detailed Problem Description
## Problem
`onAuthStateChanged()` hangs on extension service worker startup and then remains hanged until the extension service worker is restarted (either by restarting the browser or by manually reloading the extension). Note that we are using indexeddb persistence so we expect the Firebase instance to get logged in automatically whenever the service worker restarts.
## **Logging details**
We added logging into the underlying `@firebase/auth` package using `npx patch-package`, and got the hang on this case:
```javascript
tbLog('IWP: creating'); // <-- this line got printed
this.persistenceManager = await PersistenceUserManager.create(this, persistenceHierarchy); // <-- hanged here
tbLog('IWP: created'); // <-- this line never got printed
```
**PS:** Let us know if you need additional logging inside the Firebase Auth package, and what exactly. It can take us a few days to get the data.
### Steps and code to reproduce issue
We have roughly the following setup:
```javascript
import { getAuth, onAuthStateChanged, } from 'firebase/auth/web-extension';
const firebaseApp = initializeApp(firebaseConfig);
const firestore = initializeFirestore(firebaseApp, {
experimentalForceLongPolling: true
});
onAuthStateChanged(getAuth(firebaseApp), (user) => {
console.log(user);
if (user) {
enableIndexedDbPersistence(firestore, { forceOwnership: true });
}
}});
```
Note that we are using the web-extension entrypoint into firebase/auth. Note that we initialize persistence after auth has enabled. I'm not sure if it should be the other way around, I couldn't find any official docs around it, or if that matters at all.
I have attached the patch file generated using patch-package.
[@firebase+auth+1.7.1.patch](https://github.com/user-attachments/files/16868964/%40firebase%2Bauth%2B1.7.1.patch)
Contributor guide
Assessment
This issue has not been assessed yet.