Skip to content

Commit 163feff

Browse files
itigges22claude
andcommitted
fix: pass authenticated supabase client to approve/reject service
The service was using createServerSupabase() which lacks the client user's auth context in API routes. Now accepts an optional supabaseClient parameter passed from the API route handler, ensuring proper RLS context for all workflow operations. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6b1a13e commit 163feff

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

app/api/client/portal/projects/[id]/approve/route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ export async function POST(
5656
projectId: id,
5757
workflowInstanceId: validation.data.workflow_instance_id,
5858
clientUserId: user.id,
59-
notes: validation.data.notes || null
59+
notes: validation.data.notes || null,
60+
supabaseClient: supabase,
6061
});
6162

6263
return NextResponse.json({

app/api/client/portal/projects/[id]/reject/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,14 @@ export async function POST(
6262
return NextResponse.json({ error: validation.error }, { status: 400 });
6363
}
6464

65-
// Reject project
65+
// Reject project (pass authenticated supabase client for proper RLS context)
6666
const result = await clientRejectProject({
6767
projectId: id,
6868
workflowInstanceId: validation.data.workflow_instance_id,
6969
clientUserId: user.id,
7070
notes: validation.data.notes,
71-
issues: validation.data.issues || []
71+
issues: validation.data.issues || [],
72+
supabaseClient: supabase,
7273
});
7374

7475
return NextResponse.json({

lib/client-portal-service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,9 @@ export async function clientApproveProject(params: {
658658
workflowInstanceId: string;
659659
clientUserId: string;
660660
notes?: string | null;
661+
supabaseClient?: any;
661662
}): Promise<{ success: boolean; message: string; nextNodes?: Record<string, unknown>[] }> {
662-
const supabase = await getSupabase();
663+
const supabase = params.supabaseClient || await getSupabase();
663664
const { projectId, workflowInstanceId, clientUserId, notes } = params;
664665

665666
// 1. Verify client has access to this project
@@ -853,8 +854,9 @@ export async function clientRejectProject(params: {
853854
clientUserId: string;
854855
notes: string;
855856
issues?: string[];
857+
supabaseClient?: any;
856858
}): Promise<{ success: boolean; message: string }> {
857-
const supabase = await getSupabase();
859+
const supabase = params.supabaseClient || await getSupabase();
858860
const { projectId, workflowInstanceId, clientUserId, notes, issues = [] } = params;
859861

860862
// 1. Verify client has access to this project

0 commit comments

Comments
 (0)