Account Workspace API

The account workspace API allows you to retrieve all the data related to the current account.

When within the layout /home/[account] - you have access to data fetched from the account workspace API.

The data in this layout has most of the information you need around the currently selected account and the user.

To access the data, you can use the loadTeamWorkspace loader function. This function is cached per-request, so you can call it multiple times without worrying about performance.

import { loadTeamWorkspace } from '~/home/[account]/_lib/server/team-account-workspace.loader'; export default async function SomeAccountPage() { const data = await loadTeamWorkspace(); // use data }

The data returned from the loadTeamWorkspace function is an object with the following properties:

  • account: The account object
  • user: The user object coming from Supabase Auth
  • accounts: An array of all accounts the user is a member of

Here is an example of the data structure:

import type { User } from '@supabase/supabase-js'; { account: { id: string; name: string; picture_url: string; slug: string; role: string; role_hierarchy_level: number; primary_owner_user_id: string; subscription_status: string; permissions: string[]; }; user: User; accounts: Array<{ id: string | null; name: string | null; picture_url: string | null; role: string | null; slug: string | null; }>; }

The account object contains the following properties:

  1. id: The account ID
  2. name: The account name
  3. picture_url: The account picture URL
  4. slug: The account slug
  5. role: The user's role in the account
  6. role_hierarchy_level: The user's role hierarchy level
  7. primary_owner_user_id: The primary owner user ID
  8. subscription_status: The subscription status of the account. This can be 'active' | 'trialing' | 'past_due' | 'canceled' | 'unpaid' | 'incomplete' | 'incomplete_expired' | 'paused'.
  9. permissions: An array of permissions the user has in the account

Subscribe to our Newsletter
Get the latest updates about React, Remix, Next.js, Firebase, Supabase and Tailwind CSS