mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 05:12:55 -07:00
feat(auth): Improve auth dialog error handling and messaging (#11320)
This commit is contained in:
@@ -45,7 +45,9 @@ describe('validateAuthMethod', () => {
|
|||||||
it('should return an error message if GEMINI_API_KEY is not set', () => {
|
it('should return an error message if GEMINI_API_KEY is not set', () => {
|
||||||
vi.stubEnv('GEMINI_API_KEY', undefined);
|
vi.stubEnv('GEMINI_API_KEY', undefined);
|
||||||
expect(validateAuthMethod(AuthType.USE_GEMINI)).toBe(
|
expect(validateAuthMethod(AuthType.USE_GEMINI)).toBe(
|
||||||
'GEMINI_API_KEY environment variable not found. Add that to your environment and try again (no reload needed if using .env)!',
|
'GEMINI_API_KEY not found. Find your existing key or generate a new one at: https://aistudio.google.com/apikey\n' +
|
||||||
|
'\n' +
|
||||||
|
'To continue, please set the GEMINI_API_KEY environment variable or add it to a .env file.',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,7 +18,11 @@ export function validateAuthMethod(authMethod: string): string | null {
|
|||||||
|
|
||||||
if (authMethod === AuthType.USE_GEMINI) {
|
if (authMethod === AuthType.USE_GEMINI) {
|
||||||
if (!process.env['GEMINI_API_KEY']) {
|
if (!process.env['GEMINI_API_KEY']) {
|
||||||
return 'GEMINI_API_KEY environment variable not found. Add that to your environment and try again (no reload needed if using .env)!';
|
return (
|
||||||
|
'GEMINI_API_KEY not found. Find your existing key or generate a new one at: https://aistudio.google.com/apikey\n' +
|
||||||
|
'\n' +
|
||||||
|
'To continue, please set the GEMINI_API_KEY environment variable or add it to a .env file.'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ describe('AuthDialog', () => {
|
|||||||
settings: LoadedSettings;
|
settings: LoadedSettings;
|
||||||
setAuthState: (state: AuthState) => void;
|
setAuthState: (state: AuthState) => void;
|
||||||
authError: string | null;
|
authError: string | null;
|
||||||
onAuthError: (error: string) => void;
|
onAuthError: (error: string | null) => void;
|
||||||
};
|
};
|
||||||
const originalEnv = { ...process.env };
|
const originalEnv = { ...process.env };
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ interface AuthDialogProps {
|
|||||||
settings: LoadedSettings;
|
settings: LoadedSettings;
|
||||||
setAuthState: (state: AuthState) => void;
|
setAuthState: (state: AuthState) => void;
|
||||||
authError: string | null;
|
authError: string | null;
|
||||||
onAuthError: (error: string) => void;
|
onAuthError: (error: string | null) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AuthDialog({
|
export function AuthDialog({
|
||||||
@@ -174,6 +174,9 @@ Logging in with Google... Please restart Gemini CLI to continue.
|
|||||||
items={items}
|
items={items}
|
||||||
initialIndex={initialAuthIndex}
|
initialIndex={initialAuthIndex}
|
||||||
onSelect={handleAuthSelect}
|
onSelect={handleAuthSelect}
|
||||||
|
onHighlight={() => {
|
||||||
|
onAuthError(null);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
{authError && (
|
{authError && (
|
||||||
|
|||||||
@@ -33,9 +33,11 @@ export const useAuthCommand = (settings: LoadedSettings, config: Config) => {
|
|||||||
const [authError, setAuthError] = useState<string | null>(null);
|
const [authError, setAuthError] = useState<string | null>(null);
|
||||||
|
|
||||||
const onAuthError = useCallback(
|
const onAuthError = useCallback(
|
||||||
(error: string) => {
|
(error: string | null) => {
|
||||||
setAuthError(error);
|
setAuthError(error);
|
||||||
|
if (error) {
|
||||||
setAuthState(AuthState.Updating);
|
setAuthState(AuthState.Updating);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[setAuthError, setAuthState],
|
[setAuthError, setAuthState],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export interface UIActions {
|
|||||||
scope: SettingScope,
|
scope: SettingScope,
|
||||||
) => void;
|
) => void;
|
||||||
setAuthState: (state: AuthState) => void;
|
setAuthState: (state: AuthState) => void;
|
||||||
onAuthError: (error: string) => void;
|
onAuthError: (error: string | null) => void;
|
||||||
handleEditorSelect: (
|
handleEditorSelect: (
|
||||||
editorType: EditorType | undefined,
|
editorType: EditorType | undefined,
|
||||||
scope: SettingScope,
|
scope: SettingScope,
|
||||||
|
|||||||
Reference in New Issue
Block a user