import { getSupabaseServerClient } from '@kit/supabase/server-client'; export const createPageViewLog = async ({ accountId, action, }: { accountId: string; action: 'VIEW_ANALYSIS_RESULTS'; }) => { try { const supabase = getSupabaseServerClient(); const { data: { user }, error: userError, } = await supabase.auth.getUser(); if (userError || !user) { console.error('No authenticated user found; skipping audit insert'); return; } await supabase .schema('audit') .from('page_views') .insert({ account_id: accountId, action, changed_by: user.id, }) .throwOnError(); } catch (error) { console.error('Failed to insert page view log', error); } }