diff --git a/amplify.yml b/amplify.yml index 277751b..6ea8255 100644 --- a/amplify.yml +++ b/amplify.yml @@ -4,33 +4,11 @@ frontend: preBuild: commands: - npm ci - - echo "Checking for environment variables..." - - printenv | grep -E "(YOUTUBE|_SECRET)" || echo "No relevant env vars found" - - | - # Check if secrets are available through Amplify's secret mechanism - if [ ! -z "$secrets" ]; then - echo "Secrets object found" - echo "$secrets" | jq '.' 2>/dev/null || echo "Could not parse secrets" - fi build: commands: - - | - # Try multiple ways to access the secret - if [ ! -z "$YOUTUBE_API_KEY" ]; then - echo "Found YOUTUBE_API_KEY in environment" - echo "YOUTUBE_API_KEY=$YOUTUBE_API_KEY" >> .env.production - elif [ ! -z "$secrets" ] && [ ! -z "$(echo $secrets | jq -r '.YOUTUBE_API_KEY' 2>/dev/null)" ]; then - echo "Found YOUTUBE_API_KEY in secrets object" - echo "YOUTUBE_API_KEY=$(echo $secrets | jq -r '.YOUTUBE_API_KEY')" >> .env.production - elif [ ! -z "$AMPLIFY_YOUTUBE_API_KEY" ]; then - echo "Found AMPLIFY_YOUTUBE_API_KEY in environment" - echo "YOUTUBE_API_KEY=$AMPLIFY_YOUTUBE_API_KEY" >> .env.production - else - echo "WARNING: YOUTUBE_API_KEY not found in any expected location" - echo "Available env vars starting with A:" - printenv | grep "^A" | head -10 - fi - - cat .env.production 2>/dev/null || echo "No .env.production file created" + - echo "Build started on `date`" + - echo "Configuring environment variables..." + - export YOUTUBE_API_KEY="${YOUTUBE_API_KEY}" - npm run build artifacts: baseDirectory: .next @@ -39,6 +17,4 @@ frontend: cache: paths: - node_modules/**/* - - .next/cache/**/* - buildPath: / -appRoot: / \ No newline at end of file + - .next/cache/**/* \ No newline at end of file diff --git a/next.config.ts b/next.config.ts index f20d813..920d1b7 100644 --- a/next.config.ts +++ b/next.config.ts @@ -24,6 +24,14 @@ const nextConfig: NextConfig = { }, ], }, + // Make environment variables available to the browser + publicRuntimeConfig: { + YOUTUBE_API_KEY: process.env.YOUTUBE_API_KEY, + }, + // Server-side environment variables + serverRuntimeConfig: { + YOUTUBE_API_KEY: process.env.YOUTUBE_API_KEY, + }, }; export default nextConfig; diff --git a/src/app/dadvocate/page.tsx b/src/app/dadvocate/page.tsx index f8b7f78..45c15df 100644 --- a/src/app/dadvocate/page.tsx +++ b/src/app/dadvocate/page.tsx @@ -33,10 +33,14 @@ const fallbackData: Video[] = [ ]; async function getYouTubeVideos(ids: string[]): Promise { - const apiKey = process.env.YOUTUBE_API_KEY; + // Try multiple ways to get the API key + const apiKey = process.env.YOUTUBE_API_KEY || + process.env.NEXT_PUBLIC_YOUTUBE_API_KEY || + process.env.AMPLIFY_YOUTUBE_API_KEY || ''; if (!apiKey) { console.warn("YOUTUBE_API_KEY environment variable not set. Using hardcoded video titles as fallback."); + console.log("Available env vars:", Object.keys(process.env).filter(k => k.includes('YOUTUBE') || k.includes('AMPLIFY')).join(', ') || 'none'); return fallbackData; } diff --git a/src/app/gallery/page.tsx b/src/app/gallery/page.tsx index 166c8a1..bdcb3d0 100644 --- a/src/app/gallery/page.tsx +++ b/src/app/gallery/page.tsx @@ -32,10 +32,14 @@ const fallbackData: Video[] = [ ]; async function getYouTubeVideos(ids: string[]): Promise { - const apiKey = process.env.YOUTUBE_API_KEY; + // Try multiple ways to get the API key + const apiKey = process.env.YOUTUBE_API_KEY || + process.env.NEXT_PUBLIC_YOUTUBE_API_KEY || + process.env.AMPLIFY_YOUTUBE_API_KEY || ''; if (!apiKey) { console.warn("YOUTUBE_API_KEY environment variable not set. Using hardcoded video titles as fallback."); + console.log("Available env vars:", Object.keys(process.env).filter(k => k.includes('YOUTUBE') || k.includes('AMPLIFY')).join(', ') || 'none'); return fallbackData; } diff --git a/src/lib/config.ts b/src/lib/config.ts new file mode 100644 index 0000000..dd24189 --- /dev/null +++ b/src/lib/config.ts @@ -0,0 +1,7 @@ +// Configuration helper for environment variables +export const config = { + youtubeApiKey: process.env.YOUTUBE_API_KEY || process.env.NEXT_PUBLIC_YOUTUBE_API_KEY || '', +}; + +// Helper to check if we're in a server environment +export const isServer = typeof window === 'undefined'; \ No newline at end of file