Skip to content

API permission problems fail silently #107

@gpoole

Description

@gpoole

If a dataset is set to private and no/empty API key is given to createClient, the query will silently return null instead of erroring which is confusing and makes it hard to track down the problem, especially for new users.

For example, in the following case it's possible for SANITY_API_TOKEN to be undefined in the environment:

const client = createClient({
  projectId: 'xxxxxxx',
  dataset: 'production',
  apiVersion: '2022-10-21',
  useCdn: false,
  token: process.env.SANITY_API_TOKEN
})

If a query is made, the result will be null:

const result = await client.fetch(groq`
 *[_type == "somePage"]
`)
console.log(result)
// null

I understand it might be a security concern to report a failure to access a project or dataset, but on a recent project I've wasted quite a lot of time tracking the issue down, so a hint would be good. Maybe an error if undefined or null is explicitly passed to createClient?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions