Skip to content

fix(netlify): hybrid env resolution with Netlify.env.get() fallback#430

Merged
liudmylasovetovs merged 16 commits intodevelopfrom
sl/feat/db-optimization
Mar 28, 2026
Merged

fix(netlify): hybrid env resolution with Netlify.env.get() fallback#430
liudmylasovetovs merged 16 commits intodevelopfrom
sl/feat/db-optimization

Conversation

@LesiaUKR
Copy link
Copy Markdown
Collaborator

@LesiaUKR LesiaUKR commented Mar 28, 2026

Summary

Test plan

  • Netlify develop deploy succeeds without env var crashes
  • OAuth login works (Google + GitHub)
  • Email/password login still works
  • All SSR pages load (blog, quiz, shop, leaderboard)
  • Local dev (APP_ENV=local) still works via process.env

Summary by CodeRabbit

  • Refactor
    • Centralized environment variable reading for consistent configuration handling across database and authentication modules
    • Enhanced error reporting with clearer validation messages for missing configurations
    • Simplified build process by removing automatic environment generation script

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
devlovers-net Ignored Ignored Preview Mar 29, 2026 2:22pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 28, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR introduces a centralized server-side environment variable reading abstraction (readServerEnv) that prioritizes process.env with fallback to Netlify's runtime environment API. Environment variable access in database configuration, authentication setup, and proxy middleware is refactored to use this new function, while the build-time script that generated .env files is removed and its invocation in the Netlify build command is eliminated.

Changes

Cohort / File(s) Summary
Server Environment Infrastructure
frontend/lib/env/server-env.ts
New module introducing readServerEnv() that reads from process.env first, then falls back to Netlify's globalThis.Netlify?.env?.get() with string trimming and validation.
Database Configuration
frontend/db/index.ts
Replaced direct process.env access with readServerEnv() calls for APP_ENV, database URLs, and Netlify context; refactored connection selection logic to prioritize production path when DATABASE_URL is present, local path when absent but APP_ENV=local, and throw unified error otherwise.
Authentication Configuration
frontend/lib/env/auth.ts
Replaced dotenv.config() and direct process.env access with readServerEnv(); updated Google auth environment variable names to environment-suffixed keys (GOOGLE_CLIENT_ID_LOCAL/DEVELOP/PROD); added validation that throws on unresolved/invalid APP_ENV.
Proxy Middleware
frontend/proxy.ts
Removed AUTH_SECRET environment variable reading and runtime validation at module initialization (commented out); authentication flow remains unchanged.
Build Process
frontend/scripts/generate-env.sh, netlify.toml
Removed the generate-env.sh script that generated .env files from .env.example at build time; removed its invocation from the Netlify Next.js build command.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • AM1007
  • ViktorSvertoka
  • liudmylasovetovs

Poem

🐰 A hop toward harmony, environment-wise,
No more scripts to run at build-time's sunrise,
Netlify and process, in fallback they blend,
Configuration flows smooth from start to end!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: introducing hybrid environment resolution that falls back to Netlify.env.get(), which is the core issue being addressed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sl/feat/db-optimization

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@liudmylasovetovs liudmylasovetovs merged commit 5f84e73 into develop Mar 28, 2026
7 of 8 checks passed
@liudmylasovetovs liudmylasovetovs deleted the sl/feat/db-optimization branch March 28, 2026 18:17
@LesiaUKR LesiaUKR restored the sl/feat/db-optimization branch March 28, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants