@@ -6,6 +6,7 @@ import { type NextRequest, NextResponse } from 'next/server'
66import { z } from 'zod'
77import { getEmailSubject , renderPollingGroupInvitationEmail } from '@/components/emails'
88import { getSession } from '@/lib/auth'
9+ import { hasCredentialSetsAccess } from '@/lib/billing'
910import { getBaseUrl } from '@/lib/core/utils/urls'
1011import { sendEmail } from '@/lib/messaging/email/mailer'
1112
@@ -47,6 +48,15 @@ export async function GET(req: NextRequest, { params }: { params: Promise<{ id:
4748 return NextResponse . json ( { error : 'Unauthorized' } , { status : 401 } )
4849 }
4950
51+ // Check plan access (team/enterprise) or env var override
52+ const hasAccess = await hasCredentialSetsAccess ( session . user . id )
53+ if ( ! hasAccess ) {
54+ return NextResponse . json (
55+ { error : 'Credential sets require a Team or Enterprise plan' } ,
56+ { status : 403 }
57+ )
58+ }
59+
5060 const { id } = await params
5161 const result = await getCredentialSetWithAccess ( id , session . user . id )
5262
@@ -69,6 +79,15 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
6979 return NextResponse . json ( { error : 'Unauthorized' } , { status : 401 } )
7080 }
7181
82+ // Check plan access (team/enterprise) or env var override
83+ const hasAccess = await hasCredentialSetsAccess ( session . user . id )
84+ if ( ! hasAccess ) {
85+ return NextResponse . json (
86+ { error : 'Credential sets require a Team or Enterprise plan' } ,
87+ { status : 403 }
88+ )
89+ }
90+
7291 const { id } = await params
7392
7493 try {
@@ -178,6 +197,15 @@ export async function DELETE(req: NextRequest, { params }: { params: Promise<{ i
178197 return NextResponse . json ( { error : 'Unauthorized' } , { status : 401 } )
179198 }
180199
200+ // Check plan access (team/enterprise) or env var override
201+ const hasAccess = await hasCredentialSetsAccess ( session . user . id )
202+ if ( ! hasAccess ) {
203+ return NextResponse . json (
204+ { error : 'Credential sets require a Team or Enterprise plan' } ,
205+ { status : 403 }
206+ )
207+ }
208+
181209 const { id } = await params
182210 const { searchParams } = new URL ( req . url )
183211 const invitationId = searchParams . get ( 'invitationId' )
0 commit comments