Operating System
Windows 11
Environment (if applicable)
Angular 22 Application
Firebase SDK Version
12.18.0
Firebase SDK Product(s)
Auth
Project Tooling
Angular CLI, pnpm, Firebase Local Emulator Suite.
Detailed Problem Description
When calling signInWithCustomToken immediately after rapid component state changes or navigation in a Single Page Application, Firebase occasionally throws an IndexedDB error: code: undefined message: Database is closing/hidden
We noticed that issue #10318 and PR #10325 recently introduced a fix for this exact error message in 12.18.0. However, that fix appears to have only targeted signInWithPopup and background tab visibility. We are still consistently hitting this exact same race condition when using signInWithCustomToken during rapid UI changes.
If signInWithCustomToken fails here, the one-time custom token is consumed on the backend but the client session fails to persist. This permanently breaks the authentication session for our users unless we implement an aggressive retry loop to catch this specific transient database error.
Similar to #10318, the thrown error has code: undefined, which makes graceful fallback difficult without string matching the message.
Steps and code to reproduce issue
The bug is a race condition, so it happens intermittently based on component lifecycle timing.
Generate a custom token via a backend Cloud Function.
In a frontend SPA (e.g., Angular), trigger a rapid route navigation or heavy component destruction/initialization.
Immediately call signInWithCustomToken(auth, customToken).
Observe the console for the Database is closing/hidden error.
To work around this, we currently have to catch the exact error message string and retry the sign-in with a 500ms delay, which allows the IndexedDB connection to stabilize and the sign-in to succeed.
typescript
try {
await signInWithCustomToken(auth, customToken);
} catch (error) {
// Catch the unclassified database error
const isDbClosing = (error as Error)?.message?.includes('Database is closing/hidden');
if (isDbClosing) {
// Wait for the IndexedDB connection to stabilize
await new Promise(resolve => setTimeout(resolve, 500));
// Retrying succeeds
await signInWithCustomToken(auth, customToken);
} else {
throw error;
}
}
Operating System
Windows 11
Environment (if applicable)
Angular 22 Application
Firebase SDK Version
12.18.0
Firebase SDK Product(s)
Auth
Project Tooling
Angular CLI, pnpm, Firebase Local Emulator Suite.
Detailed Problem Description
When calling signInWithCustomToken immediately after rapid component state changes or navigation in a Single Page Application, Firebase occasionally throws an IndexedDB error: code: undefined message: Database is closing/hidden
We noticed that issue #10318 and PR #10325 recently introduced a fix for this exact error message in 12.18.0. However, that fix appears to have only targeted signInWithPopup and background tab visibility. We are still consistently hitting this exact same race condition when using signInWithCustomToken during rapid UI changes.
If signInWithCustomToken fails here, the one-time custom token is consumed on the backend but the client session fails to persist. This permanently breaks the authentication session for our users unless we implement an aggressive retry loop to catch this specific transient database error.
Similar to #10318, the thrown error has code: undefined, which makes graceful fallback difficult without string matching the message.
Steps and code to reproduce issue
The bug is a race condition, so it happens intermittently based on component lifecycle timing.
Generate a custom token via a backend Cloud Function.
In a frontend SPA (e.g., Angular), trigger a rapid route navigation or heavy component destruction/initialization.
Immediately call signInWithCustomToken(auth, customToken).
Observe the console for the Database is closing/hidden error.
To work around this, we currently have to catch the exact error message string and retry the sign-in with a 500ms delay, which allows the IndexedDB connection to stabilize and the sign-in to succeed.
typescript
try {
await signInWithCustomToken(auth, customToken);
} catch (error) {
// Catch the unclassified database error
const isDbClosing = (error as Error)?.message?.includes('Database is closing/hidden');
if (isDbClosing) {
// Wait for the IndexedDB connection to stabilize
await new Promise(resolve => setTimeout(resolve, 500));
} else {
throw error;
}
}