File tree Expand file tree Collapse file tree
app/api/membership/send-card Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,7 +2,10 @@ import { NextRequest, NextResponse } from 'next/server';
22import { createClient } from '@/lib/supabase/server' ;
33import { Resend } from 'resend' ;
44
5- const resend = new Resend ( process . env . RESEND_API_KEY ) ;
5+ // Create Resend client function to avoid build-time initialization
6+ function getResendClient ( ) {
7+ return new Resend ( process . env . RESEND_API_KEY ) ;
8+ }
69
710interface MembershipCardEmailData {
811 userId : string ;
@@ -259,6 +262,7 @@ export async function POST(request: NextRequest) {
259262 const membershipCardEmailContent = createMembershipCardEmail ( ) ;
260263
261264 console . log ( '📨 Sending beautiful membership card email via Resend...' ) ;
265+ const resend = getResendClient ( ) ;
262266 // Send email without PDF attachment, just the beautiful HTML template
263267 const emailResult = await resend . emails . send ( {
264268 from : 'Codeunia <connect@codeunia.com>' ,
Original file line number Diff line number Diff line change 11import { Resend } from 'resend'
22import { generateInternshipOfferLetterPDF } from '@/lib/pdf-generator'
33
4- const resend = new Resend ( process . env . RESEND_API_KEY )
4+ // Create Resend client function to avoid build-time initialization
5+ function getResendClient ( ) {
6+ return new Resend ( process . env . RESEND_API_KEY )
7+ }
58
69export interface InternshipApplicationEmailData {
710 applicantName : string
@@ -345,6 +348,7 @@ const getStatusUpdateTemplate = (data: StatusUpdateEmailData) => {
345348
346349export async function sendInternshipApplicationEmails ( data : InternshipApplicationEmailData & { applicationId : string } ) {
347350 try {
351+ const resend = getResendClient ( ) ;
348352 // Send confirmation email to applicant only
349353 const applicantTemplate = getApplicantConfirmationTemplate ( data )
350354 const applicantResult = await resend . emails . send ( {
@@ -369,6 +373,7 @@ export async function sendInternshipApplicationEmails(data: InternshipApplicatio
369373
370374export async function sendStatusUpdateEmail ( data : StatusUpdateEmailData ) {
371375 try {
376+ const resend = getResendClient ( ) ;
372377 // Don't send email if status hasn't actually changed
373378 if ( data . oldStatus === data . newStatus ) {
374379 return {
Original file line number Diff line number Diff line change 11import { createClient } from '@supabase/supabase-js' ;
22
3- // Initialize the Supabase client with environment variables
4- const supabaseUrl = process . env . NEXT_PUBLIC_SUPABASE_URL || '' ;
5- const supabaseAnonKey = process . env . NEXT_PUBLIC_SUPABASE_ANON_KEY || '' ;
3+ // Create Supabase client function to avoid build-time initialization
4+ export function getSupabaseClient ( ) {
5+ const supabaseUrl = process . env . NEXT_PUBLIC_SUPABASE_URL || '' ;
6+ const supabaseAnonKey = process . env . NEXT_PUBLIC_SUPABASE_ANON_KEY || '' ;
7+
8+ return createClient ( supabaseUrl , supabaseAnonKey , {
9+ auth : {
10+ persistSession : false , // We don't need session persistence for server-side operations
11+ } ,
12+ } ) ;
13+ }
614
7- export const supabase = createClient ( supabaseUrl , supabaseAnonKey , {
8- auth : {
9- persistSession : false , // We don't need session persistence for server-side operations
10- } ,
11- } ) ;
15+ // For backward compatibility, export a function that returns the client
16+ export const supabase = getSupabaseClient ( ) ;
1217
1318// Type for the profiles table
1419export type Profile = {
You can’t perform that action at this time.
0 commit comments