Skip to main content

checkSubscription

SolvaPay SDK


SolvaPay SDK / next/src / checkSubscription

Function: checkSubscription()

checkSubscription(request, options): Promise<SubscriptionCheckResult | NextResponse<unknown>>

Defined in: packages/next/src/index.ts:96

Check user subscription status with automatic deduplication and caching.

This Next.js helper function provides optimized subscription checking with:

  • Automatic request deduplication (concurrent requests share the same promise)
  • Short-term caching (2 seconds) to prevent duplicate sequential requests
  • Fast path optimization using cached customer references from client
  • Automatic customer creation if needed

The function:

  1. Extracts user ID from request (via requireUserId from @solvapay/auth)
  2. Gets user email and name from Supabase JWT token (if available)
  3. Validates cached customer reference (if provided via header)
  4. Ensures customer exists in SolvaPay backend
  5. Returns customer subscription information

Parameters

request

Request

Next.js request object (NextRequest extends Request)

options

CheckSubscriptionOptions = {}

Configuration options

Returns

Promise<SubscriptionCheckResult | NextResponse<unknown>>

Subscription check result with customer data and subscriptions, or NextResponse error

Example

import { NextRequest, NextResponse } from 'next/server';
import { checkSubscription } from '@solvapay/next';

export async function GET(request: NextRequest) {
const result = await checkSubscription(request);

if (result instanceof NextResponse) {
return result; // Error response
}

return NextResponse.json(result);
}

See

Since

1.0.0