import { NextResponse } from 'next/server'; import { createClient } from '@/lib/supabase/server'; /** * GET /api/subscription * 내 활성/만료 구독 목록 조회 */ export async function GET() { const supabase = await createClient(); const { data: { user }, error: authError } = await supabase.auth.getUser(); if (authError || !user) { return NextResponse.json({ error: 'UNAUTHORIZED' }, { status: 401 }); } const { data, error } = await supabase .from('subscriptions') .select('id, product_id, status, auto_renew, started_at, expires_at, cancelled_at') .eq('user_id', user.id) .order('created_at', { ascending: false }) .limit(20); if (error) { return NextResponse.json({ error: 'DB_ERROR' }, { status: 500 }); } return NextResponse.json({ ok: true, subscriptions: data ?? [] }); }