Skip to main content
GET
/
subscription
Get Subscription
curl --request GET \
  --url https://auth.nullpass.xyz/api/subscription \
  --header 'Authorization: Bearer <token>'
{
  "id": "<string>",
  "status": "<string>",
  "currentPeriodStart": 123,
  "currentPeriodEnd": 123,
  "cancelAtPeriodEnd": true,
  "plan": "<string>",
  "billingCycle": "<string>",
  "price": {
    "amount": 123,
    "currency": "<string>",
    "interval": "<string>"
  },
  "product": {
    "name": "<string>"
  }
}

Endpoint

GET /api/subscription

Overview

Retrieves subscription information for the authenticated user’s DROP service. Fetches data from Polar API and formats it for display.

Request

Requires authentication via Bearer token. User must have an active DROP service entitlement with a Polar subscription.

Response

id
string
Polar subscription ID
status
string
Subscription status (e.g., “active”, “canceled”)
currentPeriodStart
number
Current billing period start timestamp (Unix seconds)
currentPeriodEnd
number
Current billing period end timestamp (Unix seconds)
cancelAtPeriodEnd
boolean
Whether subscription will cancel at period end
plan
string
Plan name from metadata
billingCycle
string
Billing cycle (e.g., “monthly”, “yearly”)
price
object
Price information
product
object
Product information

Implementation Details

Code Reference

export async function GET(request: NextRequest) {
  const corsResponse = handleCors(request)
  if (corsResponse) return corsResponse

  const blocked = await protectRoute(request)
  if (blocked) return blocked

  const auth = await requireAuth(request)
  if ('error' in auth) return auth.error

  try {
    const entitlement = await prisma.userServiceEntitlement.findUnique({
      where: {
        userId_service: {
          userId: auth.userId,
          service: 'DROP',
        },
      },
      select: { polarSubscriptionId: true },
    })

    if (!entitlement?.polarSubscriptionId) {
      return errorResponse('No active subscription', 404, request.headers.get('origin'))
    }

    const response = await fetch(`https://api.polar.sh/v1/subscriptions/${entitlement.polarSubscriptionId}`, {
      headers: {
        'Authorization': `Bearer ${process.env.POLAR_ACCESS_TOKEN}`,
        'Content-Type': 'application/json'
      }
    })

    if (!response.ok) {
      return errorResponse('Failed to fetch subscription data', 500, request.headers.get('origin'))
    }

    const subscription = await response.json()
    
    return jsonResponse({
      id: subscription.id,
      status: subscription.status,
      currentPeriodStart: subscription.current_period_start ? new Date(subscription.current_period_start).getTime() / 1000 : 0,
      currentPeriodEnd: subscription.current_period_end ? new Date(subscription.current_period_end).getTime() / 1000 : 0,
      cancelAtPeriodEnd: subscription.cancel_at_period_end,
      plan: subscription.metadata?.plan || 'unknown',
      billingCycle: subscription.metadata?.billingCycle || 'monthly',
      price: {
        amount: subscription.price?.price_currency === 'usd' 
          ? Math.round(((subscription.price?.price_amount || 0) / 100) * 4)
          : (subscription.price?.price_amount || 0) / 100,
        currency: 'pln',
        interval: subscription.price?.recurring_interval || 'month'
      },
      product: {
        name: subscription.product?.name || 'Premium'
      }
    }, 200, request.headers.get('origin'))
  } catch (error) {
    return errorResponse('Internal server error', 500, request.headers.get('origin'))
  }
}

Status Codes

200
OK
Success
401
Unauthorized
Missing or invalid authentication token
404
Not Found
No active subscription found
500
Internal Server Error
Failed to fetch subscription data from Polar

Example Request

curl -X GET https://auth.nullpass.xyz/api/subscription \
  -H "Authorization: Bearer YOUR_TOKEN"

Example Response

{
  "id": "sub_1234567890",
  "status": "active",
  "currentPeriodStart": 1704067200,
  "currentPeriodEnd": 1706659200,
  "cancelAtPeriodEnd": false,
  "plan": "pro",
  "billingCycle": "monthly",
  "price": {
    "amount": 40,
    "currency": "pln",
    "interval": "month"
  },
  "product": {
    "name": "DROP Pro"
  }
}

Notes

  • Only works for DROP service subscriptions
  • Requires active Polar subscription ID
  • Price is converted to PLN (USD prices multiplied by 4)
  • Timestamps are returned as Unix seconds

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Response

200 - application/json

Subscription information

id
string
status
string
currentPeriodStart
integer
currentPeriodEnd
integer
cancelAtPeriodEnd
boolean
plan
string
billingCycle
string
price
object
product
object