From 56a6a9d4af2766154584a0f66d3c4d8024d74ba5 Mon Sep 17 00:00:00 2001 From: Feiyang Date: Mon, 28 Jun 2021 16:04:14 -0700 Subject: [PATCH] auto-init auth-internal after initializing auth (#5071) * auto-init auth-internal after initializing auth * Create sixty-masks-wash.md --- .changeset/sixty-masks-wash.md | 6 ++++++ packages/auth/src/exports_auth.js | 11 ++++++++++- packages/component/src/provider.ts | 9 +++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 .changeset/sixty-masks-wash.md diff --git a/.changeset/sixty-masks-wash.md b/.changeset/sixty-masks-wash.md new file mode 100644 index 00000000000..fbe46843b44 --- /dev/null +++ b/.changeset/sixty-masks-wash.md @@ -0,0 +1,6 @@ +--- +"@firebase/auth": patch +"@firebase/component": patch +--- + +Auto initialize `auth-internal` after `auth` has been initialized. diff --git a/packages/auth/src/exports_auth.js b/packages/auth/src/exports_auth.js index fbbf123818e..9f4ddc000de 100644 --- a/packages/auth/src/exports_auth.js +++ b/packages/auth/src/exports_auth.js @@ -761,7 +761,16 @@ fireauth.exportlib.exportFunction( 'multipleInstances': false, 'serviceProps': namespace, 'instantiationMode': 'LAZY', - 'type': 'PUBLIC' + 'type': 'PUBLIC', + /** + * Initialize auth-internal after auth is initialized to make auth available to other firebase products. + */ + 'onInstanceCreated': function (container, _instanceIdentifier, _instance) { + const authInternalProvider = container['getProvider']( + 'auth-internal' + ); + authInternalProvider['initialize'](); + } }; // Provides Auth internal APIs. diff --git a/packages/component/src/provider.ts b/packages/component/src/provider.ts index 290cead4eaf..716f4c78d63 100644 --- a/packages/component/src/provider.ts +++ b/packages/component/src/provider.ts @@ -251,8 +251,6 @@ export class Provider { } } - this.invokeOnInitCallbacks(instance, normalizedIdentifier); - return instance; } @@ -318,6 +316,13 @@ export class Provider { }); this.instances.set(instanceIdentifier, instance); + /** + * Invoke onInit listeners. + * Note this.component.onInstanceCreated is different, which is used by the component creator, + * while onInit listeners are registered by consumers of the provider. + */ + this.invokeOnInitCallbacks(instance, instanceIdentifier); + /** * Order is important * onInstanceCreated() should be called after this.instances.set(instanceIdentifier, instance); which