Skip to content

Commit

Permalink
fix(core/comments): ensure proper authentication config on comment cl…
Browse files Browse the repository at this point in the history
…ient

Re-use the authentication configured for the default client.
Authentication method vary if the browser supports cookies or not.
  • Loading branch information
skogsmaskin committed Oct 9, 2023
1 parent 23d4968 commit e57ba7b
Showing 1 changed file with 8 additions and 4 deletions.
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
}

0 comments on commit e57ba7b

Please sign in to comment.