Skip to Content

@osdk/react/platform-apis

Hooks for Foundry users, markings, and CBAC banners and restrictions, built on @osdk/foundry.admin.

These hooks call Foundry platform APIs with the client from OsdkProvider. Install the optional peer dependencies first:

npm install @osdk/foundry.admin @osdk/foundry.core

All hooks share these behaviors:

  • Each hook instance fetches on mount and keeps its result in component state. Results are not shared through the OSDK cache, so two components that call the same hook make two requests.
  • isLoading is true while enabled and no successful response has arrived. If the request fails, isLoading stays true alongside error, so check error first. When enabled is false, the hook does not fetch and isLoading is false.
  • refetch() reruns the request. The data field is undefined until the new response arrives.
  • error holds the request error, if any.

useCurrentFoundryUser

function useCurrentFoundryUser(
  options?: UseCurrentFoundryUserOptions,
): UseCurrentFoundryUserResult;

Gets the signed-in user.

Prop

Type

Returns { currentUser, isLoading, error, refetch }, where currentUser is a User from @osdk/foundry.admin.

useFoundryUser

function useFoundryUser(
  userId: string,
  options?: UseFoundryUserOptions,
): UseFoundryUserResult;

Gets one user by ID.

Prop

Type

Returns { user, isLoading, error, refetch }, where user is a User.

useFoundryUsersList

function useFoundryUsersList(
  options?: UseFoundryUsersListOptions,
): UseFoundryUsersListResult;

Lists users one page at a time. A page can hold more or fewer users than pageSize.

Prop

Type

Returns { users, nextPageToken, isLoading, error, refetch }. Pass nextPageToken as pageToken to load the next page; it is undefined on the last page.

useMarkings

function useMarkings(options?: UseMarkingsOptions): UseMarkingsResult;

Lists markings.

Prop

Type

Returns { markings, isLoading, error, refetch }, where markings is a Marking[].

useMarkingCategories

function useMarkingCategories(
  options?: UseMarkingCategoriesOptions,
): UseMarkingCategoriesResult;

Lists marking categories.

Prop

Type

Returns { categories, isLoading, error, refetch }, where categories is a MarkingCategory[].

useUserViewMarkings

function useUserViewMarkings(
  options?: UseUserViewMarkingsOptions,
): UseUserViewMarkingsResult;

Gets the IDs of the markings a user can view. Without userId, the hook first looks up the current user, then fetches their markings.

Prop

Type

Returns { markingIds, isLoading, error, refetch }, where markingIds is a string[].

useCbacBanner

function useCbacBanner(options: UseCbacBannerOptions): UseCbacBannerResult;

Gets the classification banner for a set of marking IDs. The hook does not fetch while markingIds is empty.

Prop

Type

Returns { banner, isLoading, error, refetch }, where banner is:

Prop

Type

useCbacMarkingRestrictions

function useCbacMarkingRestrictions(
  options: UseCbacMarkingRestrictionsOptions,
): UseCbacMarkingRestrictionsResult;

Gets the markings that a set of marking IDs implies, disallows, and requires, and whether the current user satisfies them. The hook does not fetch while markingIds is empty. It calls a preview endpoint.

Prop

Type

Returns { restrictions, isLoading, error, refetch }, where restrictions is:

Prop

Type

Example

src/CurrentUserBadge.tsx
import { useCurrentFoundryUser } from "@osdk/react/platform-apis";

export function CurrentUserBadge() {
  const { currentUser, isLoading, error } = useCurrentFoundryUser();

  return (
    <span aria-busy={isLoading}>
      {error ? "Unknown user" : (currentUser?.givenName ?? currentUser?.username)}
    </span>
  );
}

See also

On this page