-
-
Notifications
You must be signed in to change notification settings - Fork 70
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
Lazy loading FirebaseUIModule #19
Comments
Sorry for my late response. I will check that. |
OK, I could reproduce it. I'm now trying to solve it. Will keep you updated. |
- store the firebaseui instance on the window object to prevent double initialization
Ok, I found a fix. Version 0.4.4 is live now. Please give it a try and tell me if it solved the issue. |
Thank you. I'm not sure whether I'll have time today to try it. I'll inform you soon though. |
I tested it today and it seems that everything is working properly. Thank you for the fix and sorry for the late response. |
Perfect. So I close the issue. |
For anyone else arriving here by searching the error message. This is what you need to do: (Global variable is not necessary, you can prevent double initialization also with a variable in outer enough scope) |
@jkarttunen I'm not sure what you mean with that? This is a commit I did and the newest versions has this fix already in it... |
Using custom modules that are being lazy loaded and that import
FirebaseUIModule
results inError: An AuthUI instance already exists for the key "[DEFAULT]" Error: An AuthUI instance already exists for the key "[DEFAULT]
error.Consider this scenario
app.module.ts
app.routing.ts
Now the login and register feature. Each having their own module.
login.module.ts
register.module.ts
When the app redirects to either
/login
or/register
for the first time Firebase UI is presented without any problem. If the first visited path is visited next time (without visiting the other one) UI is also presented without any problem (e.g. user visits/login
consecutively several times). On the other hand if the second visited path is not same as the first visited path (e.g. user visits first/login
and then visits/register
) the error is thrown.Full error message
The error might be caused by the fact that every time
FirebaseUIModule
is imported then alsofirebaseui.service
is loaded.When a module is loaded normally it is registered in the root app injector and a service that module is also loading is injected. Now Angular can find the given service in the app root injector and provides a singleton for the whole app. No new service provider instances are created.
When a module is lazy-loaded a child injector is created and the given service is registered with that child injector.
Now, when lazy component is created it must inject the given service. The given service provider is in child injector of that lazily-loaded module. So a new instance of the service is created. This happens for each lazily-loaded module. Here it causes to create multiple AuthUI instances.
Full explanation is given here - https://angular.io/guide/ngmodule-faq#q-why-bad
The solution might be to want from developer to import
firebaseui.service
in theapp.module
and put it inproviders
so the service is available globally and not loadfirebaseui.service
infirebaseui.module
?The text was updated successfully, but these errors were encountered: