Skip to content

Fix invalid user token error #14672

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 6 commits into from
Apr 8, 2025
Merged

Fix invalid user token error #14672

merged 6 commits into from
Apr 8, 2025

Conversation

paulb777
Copy link
Member

@paulb777 paulb777 commented Apr 7, 2025

Fix a fatalError unenrolling from MFA. An invalid user token now throws an invalidUserToken error instead of crashing.

Fix #14663

google-labs-jules bot and others added 3 commits April 7, 2025 22:42
Instead of generating a fatalError in the retrieveUser function in User.swift, this change throws an invalidUserToken error. A corresponding unit test has been added to verify this new behavior.
Copy link
Contributor

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

@paulb777 paulb777 added this to the 11.12.0 - M163 milestone Apr 7, 2025
@paulb777
Copy link
Member Author

paulb777 commented Apr 7, 2025

/gemini summary

@paulb777
Copy link
Member Author

paulb777 commented Apr 7, 2025

/gemini review

Copy link
Contributor

Summary of Changes

This pull request addresses a crash that occurred when unenrolling from MFA with an invalid user token. Instead of a fatalError, the code now throws an invalidUserToken error. The change involves modifying the User.swift file to throw the new error and adding a unit test in UserTests.swift to verify the fix. A changelog entry is also added to document the fix.

Highlights

  • Error Handling: Replaces a fatalError with a more graceful invalidUserToken error when an invalid user token is encountered during MFA unenrollment.
  • Unit Testing: Adds a new unit test to specifically check the scenario where an invalid user token is used, ensuring the correct error is thrown.
  • Changelog Update: Updates the changelog to reflect the fix for the invalid user token error.

Changelog

  • FirebaseAuth/CHANGELOG.md
    • Adds a changelog entry to document the fix for the fatalError when unenrolling from MFA with an invalid user token.
  • FirebaseAuth/Sources/Swift/User/User.swift
    • Replaces fatalError("Internal FirebaseAuth Error: nil token") with throw AuthErrorUtils.invalidUserTokenError(message: "Invalid user token") when either the access token or refresh token is nil in the retrieveUser function. This prevents the app from crashing and provides a more informative error.
  • FirebaseAuth/Tests/Unit/UserTests.swift
    • Adds a new test case testRetrieveUserWithInvalidToken to verify that an invalidUserToken error is thrown when attempting to retrieve a user with a nil access token and refresh token.

Activity

  • gemini-code-assist[bot] provided general information about using Gemini Code Assist.
  • paulb777 requested a summary of the pull request.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request addresses a critical issue where an invalid user token was causing a fatalError during MFA unenrollment. The changes replace the fatalError with an invalidUserToken error, improving the application's robustness. Additionally, a new test case is added to verify the correct behavior when an invalid user token is encountered. Overall, this is a good fix with appropriate error handling and testing.

Summary of Findings

  • Error Handling: The pull request effectively replaces a fatalError with a more graceful error handling mechanism, preventing the application from crashing when an invalid user token is encountered.
  • Testing: A new test case is added to specifically verify the scenario where an invalid user token is used, ensuring that the expected error is thrown.
  • Changelog Update: The changelog is updated to reflect the fix, providing clear information about the resolved issue.

Merge Readiness

The pull request effectively addresses a critical issue and includes a new test case to ensure the fix works as expected. The changes are well-documented in the changelog. I recommend merging this pull request after addressing the review comments. I am unable to directly approve this pull request, and users should have others review and approve this code before merging.

paulb777 and others added 3 commits April 7, 2025 16:22
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@paulb777 paulb777 merged commit d3e26c0 into main Apr 8, 2025
55 checks passed
@paulb777 paulb777 deleted the fix-invalid-user-token-error branch April 8, 2025 16:55
ncooke3 pushed a commit that referenced this pull request Apr 9, 2025
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unenrolling from MFA crashes
3 participants