Skip to content

Allow to suppress Sanity warning about token used in browser context #1229

@devzom

Description

@devzom

Is your feature request related to a problem? Please describe.

I am using the custom URL builder as mentioned in https://sanity.nuxtjs.org/helpers/images#using-sanityimage-url and in browser console seeing a warning regarding the token used in browser context.

sanity.ts:5 
You have configured Sanity client to use a token in the browser. This may cause unintentional security issues. See https://www.sanity.io/help/js-client-browser-token for more information and how to hide this warning.
# sanity.ts content

import imageUrlBuilder from '@sanity/image-url'
import type { SanityImageSource } from '@sanity/image-url/lib/types/types'

export default defineNuxtPlugin(() => {
  // @ts-expect-error
  const builder = imageUrlBuilder(useSanity().config)
  function urlFor(source: SanityImageSource) {
    return builder.image(source).auto('format')
  }
  return {
    provide: { urlFor }
  }
})

additionally used ts-expect-error as in the latest version it appear that:

Argument of type 'SanityHelperConfiguration' is not assignable to parameter of type 'SanityClientLike | SanityProjectDetails | SanityModernClientLike | undefined'.
  Type 'SanityHelperConfiguration' is not assignable to type 'SanityProjectDetails'.
    Types of property 'projectId' are incompatible.
      Type 'string | undefined' is not assignable to type 'string'.
        Type 'undefined' is not assignable to type 'string'.ts(2345)

Sanity have a solution to suppress it https://www.sanity.io/docs/help/js-client-browser-token

Describe the solution you'd like to see

It's a question if something is incorrectly used or maybe it's just enough to allow to pass the specific config into nuxt.config sanity entity as:

# nuxt.config.ts
...
sanity: {
  ...
  ignoreBrowserTokenWarning: true
}

Describe alternatives you've considered

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions