@sponsorkit/sdk/server

Backend verification of a supporter's session token. No storage; runs in Workers.

On this page

@sponsorkit/sdk/server: backend verification. Works in Node, Bun, Deno, Cloudflare Workers and browsers; touches no storage.

import { … } from "@sponsorkit/sdk/server";

Example#

import { verifySession } from "@sponsorkit/sdk/server";
const fc = await verifySession(tokenFromFrontend, { github: "octocat" });
if (fc.active().length > 0) unlockPremium();

Exports#

Interfaces#

NameSummary
VerifySessionOptionsOptions for verifySession.

Functions#

NameSummary
verifySessionVerifies a supporter's session token (sks_…) forwarded by your frontend and returns their live contributions for targets.

Re-exported#

This entry point also exports these symbols, documented under @sponsorkit/sdk:

CheckoutOptions, CheckoutResult, Contribution, ContributionKind, ContributionResult, ContributionStatus, FetchLike, FinancialContribution, Frequency, Identity, isSponsorkitError, MockOption, MockPreset, Money, NagState, Provider, PROVIDERS, SponsorEntity, SPONSORKIT_ERROR_CODES, SponsorkitError, SponsorkitErrorCode, StorageFile, Supporter, TargetInfo, TargetOptions, TargetTier

Functions#

verifySession()#

async function verifySession(
  token: string,
  targets: TargetOptions | string | readonly string[],
  options: VerifySessionOptions = {},
): Promise<FinancialContribution>

Verifies a supporter's session token (sks_…) forwarded by your frontend and returns their live contributions for targets.

Throws SponsorkitError with code:

  • invalid_config: targets is missing or malformed;
  • session_invalid: the token is missing, malformed, expired or rejected;
  • targets_mismatch: the session was issued for a different target set;
  • network_error: Sponsorkit could not be reached, answered 5xx or 429, or sent an unexpected response. retryAfter holds the seconds from Retry-After when the API sent one (e.g. on 429).

Parameters

ParameterTypeDefaultDescription
tokenstringrequired
targetsTargetOptions | string | readonly string[]required{ github?, openCollective? }, a canonical target param, or a list of target strings. See TargetOptions.
optionsVerifySessionOptions{}See VerifySessionOptions.

Returns Promise<FinancialContribution> (FinancialContribution)

View source