You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After reviewing the source code, I noticed that initializeAuth() is intentionally non-idempotent when different parameters are passed (e.g., a different persistence array or popupRedirectResolver). In those cases, the SDK throws an expected exception to avoid inconsistent Auth behavior:
There are dedicated unit tests confirming this design. For example, this test explicitly verifies that re-calling initializeAuth() with a different persistence order will throw:
// packages/auth/src/core/auth/initialize.test.tsit('should throw if called again with different params (persistence)',()=>{initializeAuth(fakeApp,{persistence: [inMemoryPersistence,fakeSessionPersistence]});expect(()=>initializeAuth(fakeApp,{persistence: [fakeSessionPersistence,inMemoryPersistence]})).to.throw();});
To better understand this, I also created a minimal Next.js app using initializeAuth(), and I only observed the error after changing the configuration parameters (e.g. switching the order of persistence strategies) during a hot reload. If the parameters remain exactly the same, no error occurs. Did the error occur for you even without changing the initializeAuth configuration? I’d be happy to help contribute to that if needed.
Operating System
n/a
Environment (if applicable)
n/a
Firebase SDK Version
11.6.0
Firebase SDK Product(s)
Auth
Project Tooling
Next.js
Detailed Problem Description
getAuth
is idempotent, butinitializeAuth
is not. This causes issues with hot reloads while editing a Next.js app.Steps and code to reproduce issue
Use
initializeAuth
in a Next.js app. Start the dev server, useinitializeAuth
, and see it error.The text was updated successfully, but these errors were encountered: