Skip to content

Commit d905370

Browse files
author
Deepak Pandey
committed
πŸ”§ Fix supabaseUrl build error with proper error handling
## 🎯 Build Error Fix - βœ… Fix 'supabaseUrl is required' error during CI/CD build - βœ… Add proper environment variable checks before Supabase client creation - βœ… Implement try-catch wrapper around createClient() for graceful error handling - βœ… Return 503 status when environment variables are missing during build ## 🧹 Code Quality - βœ… Fix unused error variables in catch blocks - βœ… Improve error handling in both POST and DELETE methods - βœ… Maintain proper HTTP status codes for service unavailable scenarios ## πŸ“Š Results - βœ… Local build now completes successfully (17.2s, exit code 0) - βœ… Page data collection works without errors - βœ… CI/CD pipeline should now pass build step - βœ… Graceful degradation when environment variables unavailable
1 parent 343f3ec commit d905370

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

β€Žapp/api/events/[slug]/register/route.tsβ€Ž

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,25 @@ export async function POST(
1212
{ params }: { params: Promise<{ slug: string }> }
1313
) {
1414
try {
15-
// Skip execution during build time when environment variables are not available
15+
const { slug } = await params;
16+
17+
// Check environment variables before creating Supabase client
1618
if (!process.env.NEXT_PUBLIC_SUPABASE_URL || !process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY) {
1719
return NextResponse.json(
1820
{ error: 'Service temporarily unavailable' },
1921
{ status: 503 }
2022
);
2123
}
22-
23-
const { slug } = await params;
24-
const supabase = await createClient();
24+
25+
let supabase;
26+
try {
27+
supabase = await createClient();
28+
} catch {
29+
return NextResponse.json(
30+
{ error: 'Service temporarily unavailable' },
31+
{ status: 503 }
32+
);
33+
}
2534

2635
// Get the current user
2736
const { data: { user }, error: authError } = await supabase.auth.getUser();
@@ -123,16 +132,25 @@ export async function DELETE(
123132
{ params }: { params: Promise<{ slug: string }> }
124133
) {
125134
try {
126-
// Skip execution during build time when environment variables are not available
135+
const { slug } = await params;
136+
137+
// Check environment variables before creating Supabase client
127138
if (!process.env.NEXT_PUBLIC_SUPABASE_URL || !process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY) {
128139
return NextResponse.json(
129140
{ error: 'Service temporarily unavailable' },
130141
{ status: 503 }
131142
);
132143
}
133-
134-
const { slug } = await params;
135-
const supabase = await createClient();
144+
145+
let supabase;
146+
try {
147+
supabase = await createClient();
148+
} catch {
149+
return NextResponse.json(
150+
{ error: 'Service temporarily unavailable' },
151+
{ status: 503 }
152+
);
153+
}
136154

137155
// Get the current user
138156
const { data: { user }, error: authError } = await supabase.auth.getUser();

β€Žlib/supabase/server.tsβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { createClient as createSupabaseClient } from "@supabase/supabase-js";
33
import { cookies } from "next/headers";
44

55
export async function createClient() {
6-
const cookieStore = await cookies();
7-
86
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
97
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
108

119
if (!supabaseUrl || !supabaseAnonKey) {
1210
throw new Error('Missing Supabase environment variables');
1311
}
1412

13+
const cookieStore = await cookies();
14+
1515
return createServerClient(
1616
supabaseUrl,
1717
supabaseAnonKey,

0 commit comments

Comments
Β (0)