Skip to content

Fix authentication when used in a Plugin context #611

@jacobbudin

Description

@jacobbudin

App SDK's SanityApp does not authenticate in a Plugin (Tool) context.

To Reproduce

  1. Implement App SDK into an existing Studio as a Tool, e.g.:
const MyComponent: FunctionComponent = (): ReactElement => {
  const client = useClient()
  const {projectId, dataset} = client.config()
  const config: SanityConfig[] = [
    {
      projectId,
      dataset,
    },
  ]

  return (
    <SanityApp
      config={config}
    >
      <MySubComponent />
    </SanityApp>
  );
}

export const myTool = (): Tool => {
  return {
    component: () => <MyComponent />,
  };
}
  1. Try loading the Tool in any environment other than localhost (https://example.com)
  2. Wait for 5 seconds, the Tool will disappear and be replaced with an authentication error

Observe CORS-related failed network requests to:

Expected behavior
Authentication should persist and succeed. The Tool should load as it does on localhost.

Screenshots

Image Image

Which versions of Sanity are you using?
v3.93.0

What operating system are you using?
Not applicable

Which versions of Node.js / npm are you running?
Not applicable

See associated Sanity Discord thread.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions