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

API permission problems fail silently #107

Open
gpoole opened this issue Feb 7, 2023 · 0 comments
Open

API permission problems fail silently #107

gpoole opened this issue Feb 7, 2023 · 0 comments
Labels
🔮 Feature Request New feature or request

Comments

@gpoole
Copy link

gpoole commented Feb 7, 2023

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?

@stipsan stipsan added the 🔮 Feature Request New feature or request label Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔮 Feature Request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants