diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index cdf68059..c4cc34bf 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -62,6 +62,11 @@ jobs: npm exec -- supabase functions deploy delete-user --project-ref ${{ env.SUPABASE_PROJECT_ID }} npm exec -- supabase functions deploy seed-database --project-ref ${{ env.SUPABASE_PROJECT_ID }} + # Debug step: Verify environment variables are present before build + - name: Debug Environment Variables + run: | + echo "VITE_API_KEY is set: ${{ env.VITE_API_KEY != '' }}" + # --- Frontend Deployment --- - name: Build React Application env: diff --git a/services/geminiService.ts b/services/geminiService.ts index 072685ae..bfda2e11 100644 --- a/services/geminiService.ts +++ b/services/geminiService.ts @@ -5,18 +5,15 @@ import type { FlyerItem, MasterGroceryItem, UnitPrice, Store } from '../types'; import { CATEGORIES } from '../types'; import { parsePriceToCents } from '../utils/priceParser'; -/* -NOTE ON THE GOOGLE AI API KEY: -This project uses a Google AI (Gemini) API key. In this environment, you do not need to manually create one. -You may see a "Choose a key" dialog. If it mentions a "free tier", you can simply close or ignore that dialog. -The environment will automatically provide a free-tier API key as `process.env.API_KEY` for the AI to work. -*/ +// In a Vite project, environment variables are exposed on the `import.meta.env` object. +// For security, only variables prefixed with `VITE_` are exposed to the client-side code. +const apiKey = import.meta.env.VITE_API_KEY; -if (!process.env.API_KEY) { +if (!apiKey) { throw new Error("API_KEY environment variable not set"); } -const ai = new GoogleGenAI({ apiKey: process.env.API_KEY }); +const ai = new GoogleGenAI({ apiKey }); /** * Parses a JSON string from a Gemini response, robustly handling markdown fences. diff --git a/tsconfig.json b/tsconfig.json index 2c6eed55..3e8cc6be 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,8 @@ ], "skipLibCheck": true, "types": [ - "node" + "node", + "vite/client" // Add this line to include Vite's client-side types ], "moduleResolution": "bundler", "isolatedModules": true, diff --git a/vite.config.ts b/vite.config.ts index ee5fb8d2..95b2067f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,23 +1,16 @@ import path from 'path'; -import { defineConfig, loadEnv } from 'vite'; +import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; -export default defineConfig(({ mode }) => { - const env = loadEnv(mode, '.', ''); - return { - server: { - port: 3000, - host: '0.0.0.0', - }, - plugins: [react()], - define: { - 'process.env.API_KEY': JSON.stringify(env.GEMINI_API_KEY), - 'process.env.GEMINI_API_KEY': JSON.stringify(env.GEMINI_API_KEY) - }, - resolve: { - alias: { - '@': path.resolve(__dirname, '.'), - } - } - }; +export default defineConfig({ + server: { + port: 3000, + host: '0.0.0.0', + }, + plugins: [react()], + resolve: { + alias: { + '@': path.resolve(__dirname, '.'), + } + } });