Skip to content

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

Merged
merged 3 commits into from
Jul 1, 2021
Merged

Fix app-check-compat initialization #5089

merged 3 commits into from
Jul 1, 2021

Conversation

hsubox76
Copy link
Contributor

@hsubox76 hsubox76 commented Jul 1, 2021

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.

@changeset-bot
Copy link

changeset-bot bot commented Jul 1, 2021

⚠️ No Changeset found

Latest commit: 075f975

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Jul 1, 2021

Changeset File Check ⚠️

  • Changeset formatting error in following file:
    Package "firebase-compat-typings-test" must depend on the current version of "firebase-exp": "9.0.0-beta.5" vs "file:../../packages-exp/firebase-exp"
    Package "firebase-compat-typings-test" must depend on the current version of "firebase-exp": "9.0.0-beta.5" vs "file:../../packages-exp/firebase-exp"
    Package "firebase-compat-typings-test" must depend on the current version of "firebase-exp": "9.0.0-beta.5" vs "file:../../packages-exp/firebase-exp"
    Error: Failed to find where HEAD diverged from master. Does master exist?
        at async getChangedFilesSince (/home/runner/work/firebase-js-sdk/firebase-js-sdk/node_modules/@changesets/git/dist/git.cjs.dev.js:169:22)
        at async Object.getChangedPackagesSinceRef (/home/runner/work/firebase-js-sdk/firebase-js-sdk/node_modules/@changesets/git/dist/git.cjs.dev.js:208:24)
        at async getStatus (/home/runner/work/firebase-js-sdk/firebase-js-sdk/node_modules/@changesets/cli/dist/cli.cjs.dev.js:977:27)
        at async run$1 (/home/runner/work/firebase-js-sdk/firebase-js-sdk/node_modules/@changesets/cli/dist/cli.cjs.dev.js:1227:11)
    

@google-oss-bot
Copy link
Contributor

Size Analysis Report

Affected Products

No changes between base commit (ca85752) and head commit (c9fbc9a).

Copy link
Member

@Feiyang1 Feiyang1 left a 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, {
Copy link
Member

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.

Copy link
Member

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.

@hsubox76 hsubox76 merged commit 6ad4f58 into master Jul 1, 2021
@hsubox76 hsubox76 deleted the ch-ac-compat-init branch July 1, 2021 16:31
@firebase firebase locked and limited conversation to collaborators Aug 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants