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

Organization SDK - Fetch Organization

Learn how to use the Organization SDK to interact with the current user organization

The Organization SDK allows you to interact with the currently selected Organization. Here we list the methods available in the Organization SDK.

The example below work within a Server Components: by using the required client, you can easily adapt the code examples below to both Server Actions and Route Handlers.

The Organization's SDK is namespaced under sdk.organization - so all the methods below are available under sdk.organization.

Fetch the current Organization ID

To fetch the currently selected user's organization ID, use the getCurrentOrganizationId method:

import type { LoaderFunctionArgs } from "@remix-run/node";
import getSdk from '~/lib/sdk';
import getSupabaseServerClient from '~/core/supabase/server-client';
export async function loader(args: LoaderFunctionArgs) {
const client = getSupabaseServerClient(args.request);
const sdk = getSdk(client);
const organizationUid = await sdk.organization.getCurrentOrganizationId();
// use the organizationUid
}

The UID may be null - so do make sure to check for that. For example, you may want to redirect the user to the Organizations page if no organization is selected:

import { LoaderFunctionArgs, redirect } from "@remix-run/node";
import getSdk from '~/lib/sdk';
import getSupabaseServerClient from '~/core/supabase/server-client';
export async function loader(args: LoaderFunctionArgs) {
const client = getSupabaseServerClient(args.request);
const sdk = getSdk(client);
const organizationUid = await sdk.organization.getCurrentOrganizationId();
if (!organizationUid) {
// No organization selected
return redirect('/organizations')
}
}

Fetch the current Organization

To fetch the currently selected user's organization, use the getCurrent method:

import { LoaderFunctionArgs } from "@remix-run/node";
import getSdk from '~/lib/sdk';
import getSupabaseServerClient from '~/core/supabase/server-client';
export async function loader(args: LoaderFunctionArgs) {
const client = getSupabaseServerClient(args.request);
const sdk = getSdk(client);
const organization = await sdk.organization.getCurrent();
// use the organization
}

The getCurrent method returns the interface GetCurrentOrganizationResponse which is defined as:

interface GetCurrentOrganizationResponse {
organization: {
id: number;
name: string;
logoURL?: string | null;
// your custom fields...
subscription?: {
customerId: string | undefined;
// your custom fields...
data: {
id: string;
priceId: string;
status: Stripe.Subscription.Status;
cancelAtPeriodEnd: boolean;
currency: string | null;
interval: string | null;
intervalCount: number | null;
createdAt: string;
periodStartsAt: string;
periodEndsAt: string;
trialStartsAt: string | null;
trialEndsAt: string | null;
// your custom fields ...
}
}
}
}

Fetch the current Organization's Subscription

The organization namespace also includes a subscription namespace. This namespace allows you to interact with the current Organization's subscription.

We will show it in the next section.