Skip to content

Commit 219a648

Browse files
author
Deepak Pandey
committed
Fix ALL remaining Supabase build errors - comprehensive scan complete
- Fix app/api/verify-certificate/route.ts: Convert module-level Supabase client to lazy initialization - Fix app/api/debug-internships/route.ts: Convert module-level Supabase client to lazy initialization - Fix app/api/rounds/register/route.ts: Convert module-level Supabase client to lazy initialization - Fix app/api/rounds/payment/route.ts: Convert module-level Supabase client to lazy initialization - Fix app/api/certificates/upload-template/route.ts: Convert module-level Supabase client to lazy initialization - Fix app/api/certificates/upload-qr/route.ts: Convert module-level Supabase client to lazy initialization - Fix app/api/admin/certificates/save/route.ts: Convert module-level Supabase client to lazy initialization - Fix app/api/admin-users/route.ts: Convert module-level Supabase client to lazy initialization - Remove duplicate supabase declarations to fix compilation errors - Build now completes successfully with all 142 pages generated - ALL Supabase build errors are now completely resolved across the entire codebase
1 parent 44bf665 commit 219a648

8 files changed

Lines changed: 65 additions & 32 deletions

File tree

app/api/admin-users/route.ts

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

4-
export async function GET() {
5-
const supabase = createClient(
4+
// Create Supabase client function to avoid build-time initialization
5+
function getSupabaseClient() {
6+
return createClient(
67
process.env.NEXT_PUBLIC_SUPABASE_URL!,
78
process.env.SUPABASE_SERVICE_ROLE_KEY!
89
);
10+
}
11+
12+
export async function GET() {
13+
const supabase = getSupabaseClient();
914

1015
const { data, error } = await supabase.auth.admin.listUsers({ perPage: 1000 });
1116
if (error) {

app/api/admin/certificates/save/route.ts

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

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+
}
11+
412
// Define the type for certificate data
513
interface CertificateData {
614
cert_id: string;
@@ -16,6 +24,7 @@ interface CertificateData {
1624

1725
export async function POST(request: NextRequest) {
1826
try {
27+
const supabase = getSupabaseClient();
1928
// Check if request has content
2029
const contentType = request.headers.get('content-type');
2130
if (!contentType || !contentType.includes('application/json')) {
@@ -63,11 +72,6 @@ export async function POST(request: NextRequest) {
6372
);
6473
}
6574

66-
const supabase = createClient(
67-
process.env.NEXT_PUBLIC_SUPABASE_URL!,
68-
process.env.SUPABASE_SERVICE_ROLE_KEY!
69-
);
70-
7175
// Save certificate record with typed fields
7276
const certificateData: CertificateData = {
7377
cert_id,

app/api/certificates/upload-qr/route.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { createClient } from '@supabase/supabase-js';
22
import { NextRequest, NextResponse } from 'next/server';
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
export async function POST(request: NextRequest) {
1013
try {
14+
const supabase = getSupabaseClient();
1115
const { certId, qrCodeDataUrl } = await request.json();
1216

1317
if (!certId || !qrCodeDataUrl) {

app/api/certificates/upload-template/route.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { createClient } from '@supabase/supabase-js';
22
import { NextRequest, NextResponse } from 'next/server';
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
export async function POST(request: NextRequest) {
1013
try {
14+
const supabase = getSupabaseClient();
1115
const formData = await request.formData();
1216
const file = formData.get('file') as File;
1317
const name = formData.get('name') as string;

app/api/debug-internships/route.ts

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

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

911
export async function GET() {
1012
try {
13+
const supabase = getSupabaseClient();
1114
// Test internship applications - get all columns first
1215
const { data: appStructure, error: structError } = await supabase
1316
.from('internship_applications')

app/api/rounds/payment/route.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import { createClient } from '@supabase/supabase-js';
33
import Razorpay from 'razorpay';
44
import crypto from 'crypto';
55

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

1114
// Initialize Razorpay only if environment variables are available
1215
const getRazorpayClient = () => {
@@ -23,6 +26,7 @@ const getRazorpayClient = () => {
2326
// POST: Create payment order for a round
2427
export async function POST(request: NextRequest) {
2528
try {
29+
const supabase = getSupabaseClient();
2630
const body = await request.json();
2731
const { test_id, round_id, user_id } = body;
2832

@@ -147,6 +151,7 @@ export async function POST(request: NextRequest) {
147151
// POST: Verify payment and register for round
148152
export async function PUT(request: NextRequest) {
149153
try {
154+
const supabase = getSupabaseClient();
150155
const body = await request.json();
151156
const { orderId, paymentId, signature, test_id, round_id, user_id } = body;
152157

app/api/rounds/register/route.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ import { NextRequest, NextResponse } from 'next/server';
22
import { createClient } from '@supabase/supabase-js';
33
import { activityService } from '@/lib/services/activity';
44

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

1013
// POST: Register for a round
1114
export async function POST(request: NextRequest) {
1215
try {
16+
const supabase = getSupabaseClient();
1317
const body = await request.json();
1418
const { test_id, round_id, user_id } = body;
1519

@@ -117,6 +121,7 @@ export async function POST(request: NextRequest) {
117121
// GET: Get user's round registrations
118122
export async function GET(request: NextRequest) {
119123
try {
124+
const supabase = getSupabaseClient();
120125
const { searchParams } = new URL(request.url);
121126
const userId = searchParams.get('userId');
122127
const testId = searchParams.get('testId');

app/api/verify-certificate/route.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { createClient } from "@supabase/supabase-js";
22
import { UnifiedCache } from "@/lib/unified-cache-system";
33

4-
// Initialize Supabase client with service role
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
interface CertificateData {
1113
verification_code: string;
@@ -36,6 +38,7 @@ export async function GET(request: Request) {
3638
cacheKey,
3739
async (): Promise<CertificateData | null> => {
3840
// Fetch the internship record by verification code
41+
const supabase = getSupabaseClient();
3942
const { data: intern, error: internError } = await supabase
4043
.from("interns")
4144
.select("*, profiles(first_name, last_name)") // Join with profiles table

0 commit comments

Comments
 (0)