- subscriptions 테이블 마이그레이션 (기존 paid orders에서 자동 생성) - GET/PATCH /api/subscription: 구독 조회, 해지, 자동갱신 토글 - 마이페이지 구독 관리 탭: D-day, 해지 버튼, 자동갱신 토글 - 해지 시 만료일까지 서비스 계속 이용 가능 - Vercel Cron: 매일 01:00 KST 만료 구독 자동 처리 + 텔레그램 알림 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
28 lines
839 B
TypeScript
28 lines
839 B
TypeScript
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 ?? [] });
|
|
}
|