Skip to content

fix: improve error message when OAuth succeeds but project ID is required#21070

Merged
scidomino merged 6 commits intogoogle-gemini:mainfrom
Nixxx19:nityam/fix-auth-failed-after-success
Mar 4, 2026
Merged

fix: improve error message when OAuth succeeds but project ID is required#21070
scidomino merged 6 commits intogoogle-gemini:mainfrom
Nixxx19:nityam/fix-auth-failed-after-success

Conversation

@Nixxx19
Copy link
Contributor

@Nixxx19 Nixxx19 commented Mar 4, 2026

Summary

Fixes confusing error message when OAuth authentication succeeds but account setup requires GOOGLE_CLOUD_PROJECT. The error message now correctly reflects that OAuth succeeded but account configuration requires a project ID, removing the misleading "Failed to login" prefix.

Details

When authenticating with a workspace Google account that requires GOOGLE_CLOUD_PROJECT, the OAuth flow succeeds (showing "Authentication succeeded"), but then setupUser() throws ProjectIdRequiredError if the project ID is not set. Previously, this error was caught and displayed with a "Failed to login. Message:" prefix, which was confusing since OAuth had already succeeded.

This PR:

  • Catches ProjectIdRequiredError specifically in all three authentication error handling paths
  • Displays the error message directly without the "Failed to login" or "Failed to authenticate" prefix
  • Makes it clear that OAuth succeeded but account setup requires additional configuration

Error handling paths updated:

  1. performInitialAuth() - Initial authentication during startup
  2. useAuthCommand() - Authentication hook in UI
  3. handleAuthSelect() - Auth selection handler in AppContainer

Related Issues

Fixes #15749

How to Validate

  1. Test with workspace account requiring project ID:

    # Ensure GOOGLE_CLOUD_PROJECT is not set
    unset GOOGLE_CLOUD_PROJECT
    unset GOOGLE_CLOUD_PROJECT_ID
    
    # Start CLI
    npm start
  2. Select "Login with Google" and authenticate with a workspace account

  3. Expected behavior:

    • See "Authentication succeeded" message
    • Then see error: This account requires setting the GOOGLE_CLOUD_PROJECT or GOOGLE_CLOUD_PROJECT_ID env var. See https://goo.gle/gemini-cli-auth-docs#workspace-gca
    • Should NOT see "Failed to login. Message:" prefix
  4. Verify tests pass:

    npm test -- packages/cli/src/core/auth.test.ts packages/cli/src/ui/auth/useAuth.test.tsx

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any) - None
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

Nixxx19 added 2 commits March 4, 2026 11:12
…ired

Fixes google-gemini#15749

The issue was that OAuth authentication would succeed (showing 'Authentication succeeded'),
but then setupUser would throw ProjectIdRequiredError, which was caught and displayed as
'Failed to login. Message: ...'. This was confusing because authentication had actually
succeeded.

Now ProjectIdRequiredError is caught specifically and the error message is shown directly
without the 'Failed to login' prefix, making it clear that OAuth succeeded but account
setup requires GOOGLE_CLOUD_PROJECT to be set.
@Nixxx19 Nixxx19 requested a review from a team as a code owner March 4, 2026 07:00
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the clarity of authentication error messages within the CLI. It addresses a specific scenario where a user successfully authenticates via OAuth but their account configuration still requires a Google Cloud project ID. By catching and displaying the ProjectIdRequiredError directly, the system now provides users with precise guidance on how to resolve the issue, eliminating confusing generic login failure messages and enhancing the overall user experience during setup.

Highlights

  • Improved Error Messaging: The pull request refines error messages when OAuth authentication succeeds but a project ID is required, preventing misleading 'Failed to login' or 'Failed to authenticate' prefixes.
  • Specific Error Handling: Introduced specific handling for ProjectIdRequiredError across three key authentication paths: performInitialAuth(), useAuthCommand(), and handleAuthSelect().
  • Enhanced Test Coverage: New test cases were added to auth.test.ts and useAuth.test.tsx to ensure the ProjectIdRequiredError message is displayed correctly without the confusing prefixes.
Changelog
  • packages/cli/src/core/auth.test.ts
    • Imported ProjectIdRequiredError for testing purposes.
    • Added a new test case to verify that ProjectIdRequiredError messages are returned without the 'Failed to login' prefix.
  • packages/cli/src/core/auth.ts
    • Imported ProjectIdRequiredError to enable specific error handling.
    • Implemented a new conditional block in performInitialAuth to catch ProjectIdRequiredError and display its message directly.
  • packages/cli/src/ui/AppContainer.tsx
    • Imported ProjectIdRequiredError for use in the UI component.
    • Added a specific error handling branch in handleAuthSelect to display ProjectIdRequiredError messages without the 'Failed to authenticate' prefix.
  • packages/cli/src/ui/auth/useAuth.test.tsx
    • Imported ProjectIdRequiredError to expand testing scenarios.
    • Added a test case to confirm useAuthCommand handles ProjectIdRequiredError by showing the direct message without a 'Failed to login' prefix.
  • packages/cli/src/ui/auth/useAuth.ts
    • Imported ProjectIdRequiredError to allow for specialized error processing.
    • Integrated a new else if condition in useAuthCommand to handle ProjectIdRequiredError by presenting its message directly.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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

This pull request addresses a confusing error message by specifically handling ProjectIdRequiredError in three separate authentication flows. The changes ensure that when OAuth succeeds but a project ID is missing, the user sees a clear message about the missing configuration instead of a misleading 'Failed to login' error. The implementation is correct and is well-supported by new unit tests for each modified code path. I have one suggestion to improve consistency in error message handling.

@gemini-cli gemini-cli bot added priority/p2 Important but can be addressed in a future release. area/security Issues related to security help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Mar 4, 2026
@scidomino scidomino enabled auto-merge March 4, 2026 19:15
@scidomino scidomino added this pull request to the merge queue Mar 4, 2026
Merged via the queue into google-gemini:main with commit 8f36051 Mar 4, 2026
27 checks passed
BryanBradfo pushed a commit to BryanBradfo/gemini-cli that referenced this pull request Mar 5, 2026
struckoff pushed a commit to struckoff/gemini-cli that referenced this pull request Mar 6, 2026
kunal-10-cloud pushed a commit to kunal-10-cloud/gemini-cli that referenced this pull request Mar 12, 2026
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
yashodipmore pushed a commit to yashodipmore/geemi-cli that referenced this pull request Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/security Issues related to security help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gemini CLI Authentication failed

2 participants