This documentation is for a legacy version of Next.js and Supabase. For the latest version, please visit the Next.js and Supabase V2 documentation

The Makerkit SDK - an easy API for your Makerkit projects

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

The Makerkit SDK is a simple API for your Makerkit projects. It allows you to easily interact with the Makerkit 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

import 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

'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

import 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.

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