Skip to content

Commit 571a0fd

Browse files
committed
Fix environment variable handling for API key
1 parent 7e6b611 commit 571a0fd

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/components/CustomPairsAnalysis.jsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,20 @@ const BASE_URL = 'https://api.coingecko.com/api/v3';
6363

6464
// Read API key once from environment
6565
const COINGECKO_API_KEY = (() => {
66-
const key = import.meta.env.COINGECKO_API_KEY;
66+
// Log available environment variables in development
67+
if (import.meta.env.DEV) {
68+
console.log('Available environment variables:', Object.keys(import.meta.env));
69+
}
70+
71+
// Try both environment variable formats
72+
const key = import.meta.env.VITE_COINGECKO_API_KEY || import.meta.env.COINGECKO_API_KEY;
73+
6774
if (!key) {
68-
console.warn('CoinGecko API key not found in .env file. Using public API with lower rate limits.');
69-
} else {
70-
console.log('CoinGecko API key loaded successfully');
75+
console.warn('CoinGecko API key not found. Please check your .env file has COINGECKO_API_KEY or VITE_COINGECKO_API_KEY set.');
76+
return null;
7177
}
78+
79+
console.log('CoinGecko API key loaded successfully');
7280
return key;
7381
})();
7482

@@ -123,9 +131,9 @@ export default function CustomPairsAnalysis({ open, onClose }) {
123131
const headers = {};
124132
if (COINGECKO_API_KEY) {
125133
headers['x-cg-demo-api-key'] = COINGECKO_API_KEY;
126-
console.log('Using API key for request to:', url);
134+
console.log('Using API key for request to:', new URL(url).pathname);
127135
} else {
128-
console.log('No API key available, using public API for:', url);
136+
console.log('No API key available, using public API for:', new URL(url).pathname);
129137
}
130138

131139
// Add proxy to bypass CORS

0 commit comments

Comments
 (0)