debug: add extensive logging to subscription service

Added debug logs to getAllPlans to diagnose Bad Gateway error.
Logs will show in terminal when /admin/plans is accessed.
This commit is contained in:
2025-12-18 15:25:39 +01:00
parent 42b4b2b2e1
commit e1108addce

View File

@@ -27,25 +27,31 @@ export interface UserSubscription {
} }
/** /**
* Get all subscription plans * Get all subscription plans (admin only via RLS)
*/ */
export async function getAllPlans(): Promise<SubscriptionPlan[]> { export async function getAllPlans(): Promise<SubscriptionPlan[]> {
try { try {
console.log('[getAllPlans] Starting...');
const supabase = createServerComponentClient({ cookies }); const supabase = createServerComponentClient({ cookies });
// RLS policy will handle admin check
const { data, error } = await supabase const { data, error } = await supabase
.from('subscription_plans') .from('subscription_plans')
.select('*') .select('*')
.order('sort_order', { ascending: true }); .order('sort_order', { ascending: true });
console.log('[getAllPlans] Query result - data:', data?.length, 'error:', error);
if (error) { if (error) {
console.error('Error fetching plans:', error); console.error('[getAllPlans] Error fetching plans:', error);
// Return empty array instead of throwing
return []; return [];
} }
console.log('[getAllPlans] Returning plans:', data?.length);
return data || []; return data || [];
} catch (err) { } catch (err) {
console.error('Error in getAllPlans:', err); console.error('[getAllPlans] Exception:', err);
return []; return [];
} }
} }