Skip to content

Commit 686a96a

Browse files
committed
fix: upgrade to Node 20, fix Docker build, remove husky
1 parent 4aaf88d commit 686a96a

4 files changed

Lines changed: 47 additions & 16 deletions

File tree

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ ENV NODE_ENV=production
2525
ENV HUSKY=0
2626
ENV NEXT_OUTPUT_STANDALONE=true
2727

28+
# Required for build-time environment variable validation
29+
# These values are validated at runtime and can be placeholders for build
30+
ENV NEXT_PUBLIC_SUPABASE_URL=https://placeholder.supabase.co
31+
ENV SUPABASE_SERVICE_ROLE_KEY=placeholder_key_for_build_only
32+
ENV GOOGLE_CLIENT_ID=placeholder_for_build
33+
ENV GOOGLE_CLIENT_SECRET=placeholder_for_build
34+
ENV NEXTAUTH_SECRET=placeholder_for_build
35+
ENV JWT_SECRET=placeholder_for_build
36+
2837
# Build application
2938
RUN npm run build
3039

app/actions/auth/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {supabaseAdmin} from '@/lib/supabase-admin';
1+
import { supabaseAdmin } from '@/lib/supabase-admin';
22
import { cookies } from 'next/headers';
33
import jwt from 'jsonwebtoken';
44

lib/auth.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ export const authOptions: NextAuthOptions = {
2626
return false;
2727
}
2828
//extract dep and year from email
29-
const dep = profile.email.split('@')[1].split('.')[0];
30-
const match = profile.email.match(/_?b(\d+)@/);
29+
const dep = profile.email.split('@')[1].split('.')[0];
30+
const match = profile.email.match(/_?b(\d+)@/);
3131
const year = match ? parseInt(match[1], 10) + 2000 : null;
32-
32+
3333
// console.log(`Extracted department: ${dep}, year: ${year} from email: ${profile.email}`);
3434
// Sync user to Supabase
3535
try {
@@ -48,7 +48,7 @@ export const authOptions: NextAuthOptions = {
4848
name: profile.name || user.name,
4949
picture: profile.image || user.image,
5050
branch:dep,
51-
year: year,
51+
year: year,
5252
is_admin: 0, // Explicitly set to 0, can only be changed via Supabase
5353
}]);
5454
} else {
@@ -59,7 +59,7 @@ export const authOptions: NextAuthOptions = {
5959
name: profile.name || user.name,
6060
picture: profile.image || user.image,
6161
branch:dep,
62-
year: year,
62+
year: year,
6363
})
6464
.eq('email', profile.email);
6565
}
@@ -104,7 +104,7 @@ export const authOptions: NextAuthOptions = {
104104
if (url.includes('/api/auth/callback')) {
105105
return baseUrl + "/dashboard";
106106
}
107-
107+
108108
// Handle other redirects
109109
if (url.startsWith(baseUrl)) return url;
110110
else if (url.startsWith("/")) return new URL(url, baseUrl).toString();

lib/supabase-admin.ts

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
11
// This file is for server-side Supabase operations only
2-
import { createClient } from '@supabase/supabase-js'
2+
import { createClient, SupabaseClient } from '@supabase/supabase-js'
33

4-
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL!
5-
const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY!
4+
// Lazy initialization to avoid build-time errors
5+
// Environment variables are validated at runtime when the client is first used
6+
let supabaseAdminInstance: SupabaseClient | null = null
67

7-
// Service client for server-side operations only
8-
export const supabaseAdmin = createClient(supabaseUrl, supabaseServiceKey, {
9-
auth: {
10-
autoRefreshToken: false,
11-
persistSession: false
8+
function initSupabaseAdmin(): SupabaseClient {
9+
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL
10+
const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY
11+
12+
if (!supabaseUrl || !supabaseServiceKey) {
13+
throw new Error('Missing required Supabase environment variables. Please check your .env file.')
1214
}
13-
})
15+
16+
return createClient(supabaseUrl, supabaseServiceKey, {
17+
auth: {
18+
autoRefreshToken: false,
19+
persistSession: false
20+
}
21+
})
22+
}
23+
24+
// Export a proxy that lazily initializes the client on first access
25+
export const supabaseAdmin = new Proxy({} as SupabaseClient, {
26+
get: (_, prop) => {
27+
if (!supabaseAdminInstance) {
28+
supabaseAdminInstance = initSupabaseAdmin()
29+
}
30+
return (supabaseAdminInstance as any)[prop]
31+
}
32+
})
33+
34+
// Also export the getter function for explicit initialization
35+
export { initSupabaseAdmin as getSupabaseAdmin }

0 commit comments

Comments
 (0)