✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

Setting up document access and user tracking in Sanity Studio V3

6 replies
Last updated: Feb 27, 2023
I would like to set up a project to allow editors into Sanity Studio to create documents. However, I’d like to scope the documents they have access to, as well as save which user created the document. I have seen snippets online, but none work for me.
I’ve seen things like `

import userStore from 'part:@sanity/base/user'
but I get errors, such as
Failed to resolve import "part:@sanity/base/user

I’d like to set the value of the user as an initialValue in the document schema.
Feb 26, 2023, 1:00 AM
Do you know if you're using sanity V2 or V3?
Feb 26, 2023, 1:10 AM
V3
Feb 26, 2023, 1:49 AM
V3 no longer uses
@sanity/base
as far as I know. So you are trying to resolve a V2 import
Feb 26, 2023, 1:50 AM
This sounds like it may be of use to you https://www.sanity.io/docs/roles-reference
Feb 26, 2023, 1:52 AM
Yes, seeing that now. For instance, how would I hide the “Vision” plugin for non-admin? Would I have to get currentUser in sanity.config.js and not load the vision plugin?
Feb 26, 2023, 1:59 AM
This answer should work for you.
Feb 27, 2023, 9:01 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?