Public datasets in Sanity: Read vs Write access with tokens?

2 replies
Last updated: Dec 15, 2020
Just do be clear: Public datasets in sanity do not give write access unless you use a token? It's only public read, write always requires a token?
AI Update

That's correct! A public dataset in Sanity means public read access only. Write operations always require authentication via a token.

Here's how it breaks down:

Public Read Access means anyone can query and fetch content from your dataset without authentication. This is useful for delivering published content to your website visitors. However, even with a public dataset, certain operations still require a token:

  • Accessing draft documents (documents with . in their IDs like drafts.article-123)
  • Using the previewDrafts perspective in GROQ queries
  • Accessing any document marked as private based on custom roles

Write Access Always Requires a Token - there's no such thing as "public write access" in Sanity. Any operation that creates, updates, or deletes content requires authentication with an API token that has appropriate permissions.

This is a critical security feature. Even if your dataset is public for reading, you maintain complete control over who can modify your content. For write operations, you should use robot tokens (for production) or personal tokens (for development), and these should never be exposed in client-side code. Instead, implement write operations through:

  • Server-side code or API routes
  • Serverless functions (like Sanity Functions)
  • Backend services where the token stays secure

So yes, your understanding is spot on: public datasets = public read only, write always requires a token with appropriate permissions.

Show original thread
2 replies
Correct! And only for documents with an
_id
on the root path. https://www.sanity.io/docs/ids
Thanks Knut

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?