Files
roland-the-engineer a9431b3ba0 Refactor environment variable management with centralized validation (#45)
* Refactor environment variable management with centralized validation

- Replace plain object with Map-based env structure
- Add all environment variables (not just LlamaCloud ones)
- Use sentinel value 'mandatory-env-not-set' for required vars
- Add helper functions: isDevelopment(), isProduction(), logEnv()
- Create instrumentation.ts for one-time startup validation
- Validate environment once at server startup using Next.js hook
- Exit with error code 1 if validation fails

This ensures the app doesn't start with missing required env vars and
provides better error messages during startup.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Update services to use centralized env.get() pattern

Replace direct process.env access with env.get() in:
- OpenAI services (openai-question-extractor, multi-step-response)
- Supabase utilities (4 files)
- Database client (db.ts)
- Login actions and API routes

Also use helper functions:
- isDevelopment() and isProduction() instead of NODE_ENV checks
- Keep Vercel platform vars (VERCEL_URL, VERCEL_ENV) as process.env

Remove constructor-level env validation checks since validation now
happens once at startup.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Remove redundant validateEnv() calls from services

Remove 9 validateEnv() calls across:
- lib/llama-index-service.ts
- lib/llamaparse-service.ts
- lib/services/llamacloud-documents-service.ts
- lib/services/llamacloud-connection-service.ts
- app/api/llamacloud/projects/route.ts
- app/api/organizations/route.ts

Environment validation now happens once at startup via instrumentation.ts,
so these per-request checks are no longer needed.

Also updated env access to use env.get() pattern consistently.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Simplify next.config.ts by removing explicit env var exposure

Remove explicit env var configuration from next.config.ts.
Next.js automatically makes NEXT_PUBLIC_* variables available to the
client, so explicit exposure is unnecessary.

Keeps only essential config:
- reactStrictMode
- output: 'standalone' (for Docker deployment)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Fix remaining env.PROPERTY to env.get() conversions

Updated remaining files that were still using env.PROPERTY pattern:
- lib/llama-index-service.ts
- lib/llamaparse-service.ts
- lib/services/llamacloud-client.ts
- lib/services/llamacloud-documents-service.ts
- app/api/llamacloud/projects/route.ts
- app/api/organizations/route.ts
- app/api/projects/[projectId]/indexes/route.ts

All files now consistently use env.get('VARIABLE_NAME')! pattern.
TypeScript compilation now passes successfully.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Refactor LlamaIndexService import paths and consolidate service files

* Fix ESLint warnings in React components

Fix React Hook dependency warnings:
- ProjectDocuments: Add fetchProjectDocuments to useEffect deps
- ProjectIndexSelector: Wrap hasChanges and handleSave in useCallback
  and add all dependencies to the debounced auto-save useEffect

All ESLint checks now pass with no warnings or errors.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Add comprehensive environment variable documentation

Add detailed documentation explaining build-time vs runtime variables,
especially for NEXT_PUBLIC_* variables and Docker deployments.

Key additions:
- New "Environment Variables" section in README with comprehensive guide
- Explanation of build-time (NEXT_PUBLIC_*) vs runtime variables
- Docker deployment workflow (correct vs incorrect approaches)
- Why NEXT_PUBLIC_* variables require Docker rebuild
- Best practices for multi-environment deployments
- Code examples showing proper env.get() usage
- Startup validation explanation

This documentation is critical for users deploying with Docker, as
changing NEXT_PUBLIC_* variables without rebuilding will not work.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Implement auth for all api routes

* NODE_ENV has a default

* Make the env lookup type-safe.

* Restrict API health check path in session update logic

* Improve UI consistency

---------

Co-authored-by: Roland Tritsch <roland@tritsch.email>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-09 15:41:46 -06:00

9 lines
241 B
TypeScript

import { createBrowserClient } from '@supabase/ssr'
import { env } from '@/lib/env'
export function createClient() {
return createBrowserClient(
env.get('NEXT_PUBLIC_SUPABASE_URL')!,
env.get('NEXT_PUBLIC_SUPABASE_ANON_KEY')!
)
}