Skip to content
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

Fix error handling when fetching fresh token in App Check #8829

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nermeen-mattar
Copy link

@nermeen-mattar nermeen-mattar commented Mar 5, 2025

Fixes #8822

Issue:

When calling Firebase App Check’s getToken with forceRefresh: true while a cached token exists, if fetching a new token failed, the error is stored in internalError but not returned or thrown to third-party callers. This leads to silent failures, causing the function to return a cached token instead of propagating the error.

Impact:

This misleads the caller, who has no clue that the cached token was returned instead of a new one, preventing proper error handling. While the cached token may still be valid, forceRefresh is intended to fetch a new token, making this behavior inconsistent with its purpose.

Fix:

Now, when forceRefresh is true, the function returns both the error and token, ensuring failure is recognized.

Why This is Correct:

This aligns with the expected behavior—if forceRefresh is requested, failures should be surfaced, not masked.

Benefit:

Allows third-party apps to handle errors properly and take proper corrective actions.

@nermeen-mattar nermeen-mattar requested review from a team and hsubox76 as code owners March 5, 2025 15:17
Copy link

changeset-bot bot commented Mar 5, 2025

🦋 Changeset detected

Latest commit: f4e1391

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@firebase/app-check Minor
@firebase/app-check-compat Patch
firebase Patch

Not sure what this means? Click here to learn what changesets are.

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

@nermeen-mattar nermeen-mattar changed the title Fix force refresh error handling app check Fix app check get fresh token error handling when Mar 5, 2025
@nermeen-mattar nermeen-mattar changed the title Fix app check get fresh token error handling when Fix app check get fresh token error handling Mar 5, 2025
@nermeen-mattar nermeen-mattar changed the title Fix app check get fresh token error handling Fix error handling when fetching fresh token in App Check Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

app-check: getToken with forceRefresh:true swallows errors and returns cached token
2 participants