• Blog
  • Documentation
  • Courses
  • Changelog
  • AI Starters
  • UI Kit
  • FAQ
  • Supamode
    New
  • Pricing

Launch your next SaaS in record time with Makerkit, a React SaaS Boilerplate for Next.js and Supabase.

Makerkit is a product of Makerkit Pte Ltd (registered in the Republic of Singapore)Company Registration No: 202407149CFor support or inquiries, please contact us

About
  • FAQ
  • Contact
  • Verify your Discord
  • Consultation
  • Open Source
  • Become an Affiliate
Product
  • Documentation
  • Blog
  • Changelog
  • UI Blocks
  • Figma UI Kit
  • AI SaaS Starters
License
  • Activate License
  • Upgrade License
  • Invite Member
Legal
  • Terms of License
    • Account API
    • Team Account API
    • Authentication API
    • User Workspace API
    • Account Workspace API
    • OTP API

Account API | Next.js Supabase SaaS Kit

A quick introduction to the Account API in Makerkit

You can use the Account API for retrieving information about the personal user account.

How to use the Account API

Learn how to use the Account API in Makerkit

1

Using the Account API

2

Get the account workspace data

3

Load the user accounts

4

Get the subscription data

5

Get the billing customer ID

Using the Account API

To use the Account API, you need to import the createAccountsApi function from @kit/account/api. We need to pass a valid SupabaseClient to the function - so we can interact with the database from the server.

tsx
import { createAccountsApi } from '@kit/accounts/api';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
async function ServerComponent() {
const client = getSupabaseServerClient();
const api = createAccountsApi(client);
// use api
}

If you're in a Server Action context, you'd use:

tsx
'use server';
import { createAccountsApi } from '@kit/accounts/api';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
export async function myServerAction() {
const client = getSupabaseServerClient();
const api = createAccountsApi(client);
// use api
}

Methods

The Account API provides the following methods:

Get the account workspace data

Get the account workspace data using the getAccountWorkspace method. This method returns the workspace data for the user account.

tsx
const api = createAccountsApi(client);
const workspace = await api.getAccountWorkspace();

This is already called in the user account layout, so it's very unlikely you'll need to call this method.

Load the user accounts

Load the user accounts using the loadUserAccounts method.

This method returns an array of user accounts. Each account has a label, value, and image property.

tsx
const api = createAccountsApi(client);
const accounts = await api.loadUserAccounts();

Get the subscription data

Get the subscription data for the given user using the getSubscription method.

This method returns the subscription data for the given user account.

tsx
const api = createAccountsApi(client);
const subscription = await api.getSubscription(accountId);

Returns the table subscriptions and subscription_items.

Get the billing customer ID

Get the billing customer ID for the given user using the getCustomerId method.

This method returns the billing customer ID for the given user account.

tsx
const api = createAccountsApi(client);
const customerId = await api.getCustomerId(accountId);
On this page
  1. Using the Account API
    1. Methods
      1. Get the account workspace data
      2. Load the user accounts
      3. Get the subscription data
      4. Get the billing customer ID