@@ -8,14 +8,12 @@ export async function GET() {
88 try {
99 const session = await getSession ( ) ;
1010
11- if ( ! session ?. user ?. id ) {
12- return NextResponse . json ( { error : 'Unauthorized' } , { status : 401 } ) ;
13- }
14-
15- let hasActiveSubscription = true ; // Assume true by default or if Stripe disabled
11+ // Default to allowing access. If Stripe is enabled and the requester is authenticated, evaluate their subscription.
12+ let hasActiveSubscription = true ;
1613
17- if ( process . env . STRIPE_ENABLED === 'true' ) {
14+ if ( process . env . STRIPE_ENABLED === 'true' && session ?. user ?. id ) {
1815 const subscription = await getActiveSubscriptionByUserId ( { userId : session . user . id } ) ;
16+
1917 if ( subscription ) {
2018 if ( subscription . status === 'active' ) {
2119 hasActiveSubscription = true ;
@@ -31,10 +29,13 @@ export async function GET() {
3129 } else {
3230 hasActiveSubscription = false ;
3331 }
32+
3433 console . log ( `[api/user/subscription-status] User: ${ session . user . id } , Sub Status: ${ subscription ?. status } , HasActive: ${ hasActiveSubscription } ` ) ;
34+ } else if ( process . env . STRIPE_ENABLED === 'true' ) {
35+ // Stripe is enabled but there's no authenticated user; default to granting access.
36+ console . log ( '[api/user/subscription-status] No authenticated user detected. Granting access by default.' ) ;
3537 } else {
36- console . log ( `[api/user/subscription-status] Stripe DISABLED, granting access.` ) ;
37- hasActiveSubscription = true ;
38+ console . log ( '[api/user/subscription-status] Stripe DISABLED, granting access.' ) ;
3839 }
3940
4041 return NextResponse . json ( { hasActiveSubscription } ) ;
0 commit comments