Fix build for missing Supabase env vars#35
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces fallbacks and guards around missing Supabase environment variables to prevent build and runtime errors when Supabase is unconfigured.
- Provide placeholder URL/anon key and expose
isSupabaseConfiguredflag. - Guard client/server creation and service methods (blog & auth) to skip Supabase calls.
- Update context and test component to handle and display missing Supabase config.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/supabase/client.ts | Added placeholder env defaults, isSupabaseConfigured, and guard in createServerClient. |
| lib/services/blog.service.ts | Early-return branches when Supabase is unconfigured with console warnings. |
| lib/auth/auth.service.ts | Added config checks in each auth method and default behavior in onAuthStateChange. |
| contexts/AuthContext.tsx | Wraps auth-state subscription in isSupabaseConfigured check. |
| components/SupabaseConnectionTest.tsx | Shows error message if Supabase isn’t configured before testing. |
Comments suppressed due to low confidence (2)
components/SupabaseConnectionTest.tsx:12
- We should add unit or integration tests for the branch where Supabase isn’t configured to verify that the component shows the error state as expected.
if (!isSupabaseConfigured) {
lib/auth/auth.service.ts:224
- The fallback return of
{ data: null }inonAuthStateChangedoesn’t include asubscriptionproperty, which consumers expect. Consider returning{ data: { subscription: null } }for a consistent interface.
if (!isSupabaseConfigured) {
|
|
||
| // Get posts with filtering and pagination | ||
| async getPosts(params: BlogSearchParams = {}): Promise<BlogPaginatedResponse> { | ||
| if (!isSupabaseConfigured) { |
There was a problem hiding this comment.
There's a lot of repeated if (!isSupabaseConfigured) boilerplate across service methods. Consider extracting this pattern into a higher-order function or wrapper to reduce duplication and improve readability.
| if (!isSupabaseConfigured) { | ||
| throw new Error('Supabase environment variables are not configured') | ||
| } | ||
| return createClient<Database>(supabaseUrl!, supabaseAnonKey!) |
There was a problem hiding this comment.
The non-null assertions (!) on supabaseUrl and supabaseAnonKey are redundant since they always have a fallback string value. You can remove the ! operators.
| return createClient<Database>(supabaseUrl!, supabaseAnonKey!) | |
| return createClient<Database>(supabaseUrl, supabaseAnonKey) |
Summary
Testing
npm run lintnpm run buildnpm testnpm run test:e2e(fails: WebServer warnings, ended manually)npm run test:a11y(fails: missing script)https://chatgpt.com/codex/tasks/task_e_6868147445088325b02768260de8b28e