fix(auth): improve API key authentication flow (#13829)

This commit is contained in:
Gal Zahavi
2025-11-26 13:58:14 -08:00
committed by GitHub
parent 0d29385e1b
commit b2bdfcf1b5
4 changed files with 71 additions and 18 deletions
+17
View File
@@ -214,6 +214,23 @@ describe('useAuth', () => {
});
});
it('should prioritize env key over stored key when both are present', async () => {
mockLoadApiKey.mockResolvedValue('stored-key');
process.env['GEMINI_API_KEY'] = 'env-key';
const { result } = renderHook(() =>
useAuthCommand(createSettings(AuthType.USE_GEMINI), mockConfig),
);
await waitFor(() => {
expect(mockConfig.refreshAuth).toHaveBeenCalledWith(
AuthType.USE_GEMINI,
);
expect(result.current.authState).toBe(AuthState.Authenticated);
// The environment key should take precedence
expect(result.current.apiKeyDefaultValue).toBe('env-key');
});
});
it('should set error if validation fails', async () => {
mockValidateAuthMethod.mockReturnValue('Validation Failed');
const { result } = renderHook(() =>