fix: use dynamic tenant_id from user session for html dashboard

This commit is contained in:
Marcos Fargas
2026-10-04 23:30:30 +02:00
parent fff5bf1ca2
commit d56ba63f17

View File

@@ -1,29 +1,29 @@
import { NextResponse } from 'next/server'; import { NextResponse } from 'next/server';
import { htmlTemplate } from './template'; import { htmlTemplate } from './template';
import fs from 'fs';
import path from 'path';
import { createClient } from '@/lib/supabase/server'; import { createClient } from '@/lib/supabase/server';
import { resolveActiveTenant } from '@/lib/tenant-context';
export async function GET() { export async function GET() {
const supabase = await createClient(); const supabase = await createClient();
const tenant_id = '8bec977a-6032-4759-aa7f-b5042081f450'; const { data: { user } } = await supabase.auth.getUser();
if (!user) {
return new NextResponse('Unauthorized', { status: 401 });
}
const { data: adDaily } = await supabase const ctx = await resolveActiveTenant(user);
.from('ad_daily') const tenant_id = ctx.tenantId;
.select('*')
.eq('tenant_id', tenant_id)
.order('day', { ascending: true });
const { data: orgDaily } = await supabase let queryAd = supabase.from('ad_daily').select('*').order('day', { ascending: true });
.from('organic_daily') if (tenant_id) queryAd = queryAd.eq('tenant_id', tenant_id);
.select('*') const { data: adDaily } = await queryAd;
.eq('tenant_id', tenant_id)
.order('day', { ascending: true });
const { data: creativePipeline } = await supabase let queryOrg = supabase.from('organic_daily').select('*').order('day', { ascending: true });
.from('creative_pipeline') if (tenant_id) queryOrg = queryOrg.eq('tenant_id', tenant_id);
.select('*') const { data: orgDaily } = await queryOrg;
.order('created_at', { ascending: true });
let queryPipe = supabase.from('creative_pipeline').select('*').order('created_at', { ascending: true });
if (tenant_id) queryPipe = queryPipe.eq('tenant_id', tenant_id);
const { data: creativePipeline } = await queryPipe;
// Map to K format // Map to K format
const startDay = new Date(); const startDay = new Date();