Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core/comments): ensure authentication config on comment client #4983

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions packages/sanity/src/core/comments/hooks/useCommentsClient.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
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,
requestTagPrefix: 'sanity.studio',
useCdn: false,
withCredentials: true,
})
}, [dataset, projectId])
}, [dataset, originalClient, projectId])

return client
}
Loading