fix(auth): prioritize GEMINI_API_KEY env var and skip unnecessary key…#14745
fix(auth): prioritize GEMINI_API_KEY env var and skip unnecessary key…#14745
Conversation
…chain access When GEMINI_API_KEY is present in the environment, the application now uses it immediately without attempting to load credentials from the system keychain. This prevents unnecessary keychain access prompts for users who rely solely on environment variables.
Summary of ChangesHello @galz10, 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 refines the authentication mechanism by ensuring that the Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request aims to prioritize the GEMINI_API_KEY environment variable and optimize authentication by skipping unnecessary key loading. While the intention is good, the implementation introduces a subtle but important bug in both modified files. The use of the logical OR operator (||) to check for the environment variable's presence causes an explicitly empty GEMINI_API_KEY to be ignored, incorrectly falling back to a stored key. My review includes comments with high severity to address this by using checks that correctly handle an empty string as a valid, intentional value, ensuring the environment variable behavior is predictable and correct.
|
Size Change: +1.16 kB (+0.01%) Total Size: 21.6 MB
ℹ️ View Unchanged
|
0ea18e4 to
37f086b
Compare
c6dd376 to
bd6fd6c
Compare
|
when I login with oauth and then log in with a key I still get the dialog to enter an API key even though I already have one exported in my ENV. I should not see the API KEY entry dialog at all if GEMINI_API_KEY is set |
- Updates ApiAuthDialog to use Ctrl+C for clearing stored keys instead of Ctrl+K. - Modifies AuthDialog to skip the API key input dialog if GEMINI_API_KEY is present in the environment, even on re-authentication. - Adds a key to ApiAuthDialog in DialogManager to ensure the component re-mounts when the default value changes. - Updates tests to verify that empty environment variables are handled correctly and that the dialog is skipped when env vars are present.
Fixed |
fda2897 to
f83f83f
Compare
|
This review was generated by Gemini CLI. Reviewing the changes to prioritize Logic & Correctness:
Tests:
Code Unreachability: const initialApiKey = process.env['GEMINI_API_KEY'] || defaultValue;It seems this line might effectively be dead code because:
React:
Overall, looks good! |
|
In Example: // const pendingPromise = useRef<{ cancel: () => void } | null>(null);
// useEffect(() => () => pendingPromise.current?.cancel(), []);
//
// const handleClear = () => {
// pendingPromise.current?.cancel();
// const { promise, cancel } = makeCancellable(clearApiKey());
// pendingPromise.current = { cancel };
// promise.then(() => buffer.setText(''));
// }; |
jacob314
left a comment
There was a problem hiding this comment.
Approved once the two comments mentioned are addressed.
- Implement cancelable promise pattern for API key clearing to safely handle component unmounting - Transition to using shared keyMatchers for the clear input command to ensure consistent keyboard shortcuts
…r and skip unnecessary key… (google-gemini#14745)

Summary
This PR updates the authentication logic to prioritize the
GEMINI_API_KEYenvironment variable over the system keychain. This prevents unnecessary keychain access prompts for users who have configured the CLI via environment variables.Details
Previously, the application would unconditionally attempt to load credentials from the system keychain on startup, even if a valid
GEMINI_API_KEYwas present in the environment. This often triggered system prompts (e.g., macOS Keychain Access) or errors in environments where keychain access is restricted or unwanted.This change refactors
useAuth.tsto:process.env['GEMINI_API_KEY']first.loadApiKey()(keychain access) if the environment variable is missing.Additionally,
ApiAuthDialog.tsxhas been updated to initialize the text buffer with the environment variable value if available, improving the UI experience.Related Issues
Related to internal ticket: manual-request-prevent-keychain-access
How to Validate
Setup Environment Variable:
Run the CLI:
Expected Result:
Verify Fallback (Edge Case):
unset GEMINI_API_KEY).Pre-Merge Checklist