Skip to content

Commit

Permalink
fix(config): respect unstable_clientFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuslundgard authored and rexxars committed Dec 13, 2022
1 parent 543a0f3 commit bcd4854
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions packages/sanity/src/core/config/prepareConfig.ts
@@ -1,6 +1,6 @@
/* eslint-disable max-nested-callbacks */

import {SanityClient} from '@sanity/client'
import createClient, {SanityClient} from '@sanity/client'
import {map, shareReplay} from 'rxjs/operators'
import {CurrentUser, Schema} from '@sanity/types'
import {studioTheme} from '@sanity/ui'
Expand Down Expand Up @@ -88,10 +88,12 @@ export function prepareConfig(config: Config): PreparedConfig {
const sources = [rootSource as SourceOptions, ...nestedSources]

const resolvedSources = sources.map((source): InternalSource => {
const clientFactory = source.unstable_clientFactory || createClient

const projectId = source.projectId
const dataset = source.dataset

const auth = source.auth || createAuthStore({dataset, projectId})
const auth = source.auth || createAuthStore({clientFactory, dataset, projectId})

let schemaTypes
try {
Expand Down
@@ -1,4 +1,4 @@
import createClient, {SanityClient} from '@sanity/client'
import {ClientConfig as SanityClientConfig, SanityClient} from '@sanity/client'
import {defer} from 'rxjs'
import {map, shareReplay, startWith, switchMap} from 'rxjs/operators'
import {memoize} from 'lodash'
Expand All @@ -19,6 +19,7 @@ export interface AuthProvider {

/** @internal */
export interface AuthStoreOptions {
clientFactory: (options: SanityClientConfig) => SanityClient
projectId: string
dataset: string
/**
Expand Down Expand Up @@ -137,6 +138,7 @@ const getCurrentUser = async (
* @internal
*/
export function _createAuthStore({
clientFactory,
projectId,
dataset,
loginMethod = 'dual',
Expand All @@ -159,7 +161,7 @@ export function _createAuthStore({
// // see above
// debounce(() => firstMessage),
map((token) =>
createClient({
clientFactory({
projectId,
dataset,
apiVersion: '2021-06-07',
Expand Down Expand Up @@ -198,7 +200,7 @@ export function _createAuthStore({

async function handleCallbackUrl() {
if (sessionId && loginMethod === 'dual') {
const requestClient = createClient({
const requestClient = clientFactory({
projectId,
dataset,
useCdn: true,
Expand Down Expand Up @@ -231,7 +233,7 @@ export function _createAuthStore({
}

async function logout() {
const requestClient = createClient({
const requestClient = clientFactory({
projectId,
dataset,
useCdn: true,
Expand Down

1 comment on commit bcd4854

@vercel
Copy link

@vercel vercel bot commented on bcd4854 Dec 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

test-studio – ./

test-studio-git-next.sanity.build
test-studio.sanity.build

Please sign in to comment.