1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
import { NextResponse } from "next/server"
import { createSupabaseAdminClient } from "@/lib/supabase/admin"
import { authenticateApiRequest } from "@/lib/api-auth"
import { TIER_LIMITS, type SubscriptionTier } from "@asa-news/shared"
export async function GET(request: Request) {
const authResult = await authenticateApiRequest(request)
if (!authResult.authenticated) {
return NextResponse.json(
{ error: authResult.error },
{ status: authResult.status }
)
}
const adminClient = createSupabaseAdminClient()
const { data: profile, error } = await adminClient
.from("user_profiles")
.select(
"tier, feed_count, folder_count, muted_keyword_count, custom_feed_count"
)
.eq("id", authResult.user.userIdentifier)
.single()
if (error || !profile) {
return NextResponse.json(
{ error: "Failed to load profile" },
{ status: 500 }
)
}
const tierLimits = TIER_LIMITS[profile.tier as SubscriptionTier]
return NextResponse.json({
profile: {
tier: profile.tier,
feedCount: profile.feed_count,
folderCount: profile.folder_count,
mutedKeywordCount: profile.muted_keyword_count,
customFeedCount: profile.custom_feed_count,
limits: {
maximumFeeds: tierLimits.maximumFeeds,
maximumFolders: tierLimits.maximumFolders,
maximumMutedKeywords: tierLimits.maximumMutedKeywords,
maximumCustomFeeds: tierLimits.maximumCustomFeeds,
},
},
})
}
|