-
Notifications
You must be signed in to change notification settings - Fork 945
Fix app-check-compat initialization #5089
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
Conversation
|
Changeset File Check
|
Size Analysis Report |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should set the instantiation mode of components app-check-exp
and app-check-internal
to explicit by chaining .setInstantiationMode(InstantiationMode.EXPLICIT)
when creating the components.
@@ -47,24 +49,42 @@ export class AppCheckService implements FirebaseAppCheck, _FirebaseService { | |||
} else { | |||
provider = new CustomProvider({ getToken: siteKeyOrProvider.getToken }); | |||
} | |||
initializeAppCheck(this.app, { | |||
this._delegate = initializeAppCheck(this.app, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should check if AppCheck is already initialized first. If it is, we will just get it through provider.getImmediate()
; This can happen if both app-check and app-check-compat are included in an app and app-check is initialized first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, that doesn't seem to be a valid use case because people need to provide a provider to activate
, so if they are using app-check-compat, they should use activate
and never call initializeAppCheck()
from the modular package.
Try to fix app-check-compat's activate() incorrectly throwing an error that app check has already been initialized. This happens because app-check-compat's factory initializes app-check-exp, which means when the compat activate() calls exp's initializeAppCheck() it is too late, it has already been initialized.
This approach avoids initializing app-check-exp until activate() is called. This means the AppCheck compat service's _delegate is going to be empty at initialization. That should be fine because all the other app check compat methods can throw an error asking the user to call activate() first. I think app check compat should have its own error anyway. If they hit the error in the called exp function, it asks you to "call initializeAppCheck() first" which doesn't exist in compat.