Getting user data in a Sanity query and using a person document type for authors
Unfortunately, Sanity doesn't provide built-in system fields for tracking which user created or modified a document. The system fields available on documents are:
_id- Unique identifier_type- Document type_rev- Revision tracking_createdAt- Timestamp when created_updatedAt- Timestamp when last modified
Notice there's no _createdBy or _updatedBy field that you can query.
Workarounds
If you need to track document creators, you have a couple of options:
1. Manual author field in your schema
Add an author/creator field to your document schema that references a user document:
defineField({
name: 'author',
type: 'reference',
to: [{type: 'person'}]
})You'd need to manually create person documents for each Sanity user and set this field when creating content.
2. Use Initial Value Templates
You can use Initial Value Templates to automatically populate the author field when a document is created, though this still requires manual setup.
3. Use the History API for audit trails
While you can't query it directly in GROQ, the History API does track transaction history including user information. This is useful for audit trails but not for querying documents by creator in your content queries.
There's a community discussion with a script example for creating person documents from Sanity users if you want to automate the initial setup.
The lack of built-in creator tracking is a common limitation in headless CMS systems where the content authoring layer is separated from the content data layer.
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.