Sanity Library Reference Docs
    Preparing search index...

    Function getProjectAccessErrorProjectId

    • Returns the ID of the project that rejected a request because the signed-in user isn't a member of it. The Content Lake reports this as a 401 projectUserNotFoundError. It usually means the user signed in with a different account than the one that has access, for example Google instead of SSO with the same email address.

      When this error reaches the SDK's AuthBoundary, the boundary replaces the whole app with a screen that explains the problem. An app-level error boundary inside AuthBoundary catches the error first, so it decides where the error goes. Rethrow it when the app can't work without the rejected project. Handle it in place when only part of the app reads from that project, so a user who can access the app's other projects can keep using them.

      Parameters

      • error: unknown

        The value to inspect. A ClientError, or an error that wraps one as its cause.

      Returns string | null

      The rejected project's ID, or null when the error isn't a projectUserNotFoundError or the response doesn't name the project.

      const MAIN_PROJECT_ID = 'abc123'

      function Fallback({error}: FallbackProps) {
      const projectId = getProjectAccessErrorProjectId(error)
      // The app can't work without its main project, so let AuthBoundary
      // replace it with the project access screen.
      if (projectId === MAIN_PROJECT_ID) throw error
      if (projectId) return <p>You don't have access to project {projectId}.</p>
      return <p>Something went wrong.</p>
      }