Breadcrumbs

The NextKit SDK

The NextKit SDK is a simple API for your NextKit projects. It allows you to easily interact with the NextKit core entities


The NextKit SDK is a simple API for your NextKit projects. It allows you to easily interact with the NextKit core entities, such as: Users, Organizations, Subscriptions and Memberships.

As you build your application, you will need to interact with the core entities. The SDK provides a simple way to do that.

Usage

Initializing the SDK is simple. You will need to provide any of the Supabase Server clients - depending on where you are using the SDK (route, server component or server action).

Server Components

In the example below, we initialize the SDK in a Server Component

tsimport getSdk from '~/lib/sdk';
import getSupabaseServerComponentClient from '~/core/supabase/server-component-client';
 
async function PageServerComponent() {
  const client = getSupabaseServerComponentClient();
  const sdk = getSdk(client);
 
  // ...
}

Server Actions

In the example below, we initialize the SDK in a Server Action

ts'use server';
 
import getSdk from '~/lib/sdk';
import getSupabaseServerActionClient from '~/core/supabase/server-action-client';
 
export async function myServerAction() {
  const client = getSupabaseServerActionClient();
  const sdk = getSdk(client);
 
  // ...
}

Route Handlers

In the example below, we initialize the SDK in a Route Handler

tsimport getSupabaseRouteHandlerClient from '~/core/supabase/route-handler-client';
import getSdk from '~/lib/sdk';
 
export async function GET() {
  const client = getSupabaseRouteHandlerClient();
  const sdk = getSdk(client);
 
  // ...
}

Client Side

You may also initialize the SDK on the client side - but bear in mind some API are not going to work in non-server environments. This is useful if you need to interact with the core entities on the client side.

tsimport useSupabase from '~/core/supabase/use-supabase';
 
export function useSdk() {
  const client = useSupabase();
  return getSdk(client);
}