diff --git a/packages/sanity/src/core/comments/hooks/useCommentsClient.ts b/packages/sanity/src/core/comments/hooks/useCommentsClient.ts index 7e6d52ef69f7..ca4078a9dd7d 100644 --- a/packages/sanity/src/core/comments/hooks/useCommentsClient.ts +++ b/packages/sanity/src/core/comments/hooks/useCommentsClient.ts @@ -1,13 +1,17 @@ -import {SanityClient, createClient} from '@sanity/client' +import {SanityClient} from '@sanity/client' import {useMemo} from 'react' import {useWorkspace} from '../../studio' +import {useClient} from '../../hooks' export function useCommentsClient(): SanityClient { const {dataset, projectId} = useWorkspace() - + const originalClient = useClient() // Initialize client scoped to adjacent metacontent dataset + // It's a clone of the default client for the studio, + // in order to have the authentication properly configured + // based on cookie support (use JWT auth if cookies are not supported) const client = useMemo(() => { - return createClient({ + return originalClient.withConfig({ apiVersion: 'v2022-05-09', dataset: `${dataset}-metacontent-comments`, projectId, @@ -15,7 +19,7 @@ export function useCommentsClient(): SanityClient { useCdn: false, withCredentials: true, }) - }, [dataset, projectId]) + }, [dataset, originalClient, projectId]) return client }