Skip to content

Commit 7c9b08b

Browse files
author
Deepak Pandey
committed
Fix remaining Supabase build errors
- Fix admin/internships and admin/rounds routes with lazy Supabase client initialization - All API routes now use getSupabaseClient() function instead of module-level initialization - This resolves all remaining 'supabaseUrl is required' build errors - Build, tests, and security checks all pass successfully
1 parent 69ef228 commit 7c9b08b

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

app/api/admin/internships/route.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { NextResponse } from "next/server";
22
import { createClient } from "@supabase/supabase-js";
33

4-
// Admin Internships CRUD using service role key
5-
const supabase = createClient(
6-
process.env.NEXT_PUBLIC_SUPABASE_URL!,
7-
process.env.SUPABASE_SERVICE_ROLE_KEY!
8-
);
4+
// Create Supabase client function to avoid build-time initialization
5+
function getSupabaseClient() {
6+
return createClient(
7+
process.env.NEXT_PUBLIC_SUPABASE_URL!,
8+
process.env.SUPABASE_SERVICE_ROLE_KEY!
9+
);
10+
}
911

1012
// List all internships
1113
export async function GET() {
14+
const supabase = getSupabaseClient();
1215
const { data, error } = await supabase
1316
.from("interns")
1417
.select(
@@ -35,6 +38,7 @@ export async function GET() {
3538
// Create a new internship
3639
export async function POST(request: Request) {
3740
const body = await request.json();
41+
const supabase = getSupabaseClient();
3842
const { data, error } = await supabase
3943
.from("interns")
4044
.insert([body])
@@ -57,6 +61,7 @@ export async function PATCH(request: Request) {
5761
return NextResponse.json({ error: "Missing key { email, domain, start_date }" }, { status: 400 });
5862
}
5963

64+
const supabase = getSupabaseClient();
6065
const { data, error } = await supabase
6166
.from("interns")
6267
.update(fields)
@@ -79,6 +84,7 @@ export async function DELETE(request: Request) {
7984
return NextResponse.json({ error: "Missing key { email, domain, start_date }" }, { status: 400 });
8085
}
8186

87+
const supabase = getSupabaseClient();
8288
const { error } = await supabase
8389
.from("interns")
8490
.delete()

app/api/admin/rounds/route.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { NextRequest, NextResponse } from 'next/server';
22
import { createClient } from '@supabase/supabase-js';
33

4-
const supabase = createClient(
5-
process.env.NEXT_PUBLIC_SUPABASE_URL!,
6-
process.env.SUPABASE_SERVICE_ROLE_KEY!
7-
);
4+
// Create Supabase client function to avoid build-time initialization
5+
function getSupabaseClient() {
6+
return createClient(
7+
process.env.NEXT_PUBLIC_SUPABASE_URL!,
8+
process.env.SUPABASE_SERVICE_ROLE_KEY!
9+
);
10+
}
811

912
// GET: Get rounds for a specific test
1013
export async function GET(request: NextRequest) {
@@ -19,6 +22,7 @@ export async function GET(request: NextRequest) {
1922
);
2023
}
2124

25+
const supabase = getSupabaseClient();
2226
const { data: rounds, error } = await supabase
2327
.from('test_rounds')
2428
.select('*')
@@ -66,6 +70,7 @@ export async function POST(request: NextRequest) {
6670
);
6771
}
6872

73+
const supabase = getSupabaseClient();
6974
const { data: round, error } = await supabase
7075
.from('test_rounds')
7176
.insert({

0 commit comments

Comments
 (0)