Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Controlling Desk sidebar based on user attributes

4 replies
Last updated: Jun 22, 2023
I am wanting to control what is in the Desk sidebar (like Settings, etc) based on the current user attributes like their role, or even down to a specific user’s email address. However if I call
useCurrentUser
from inside
sanity.config.ts
I get a nasty warning and I realize that it is because I’m using a hook and it is not inside a React component. My question is where would be the best place to make this call, or is there another “non-hook” way to go about getting the currently logged in user? Thanks for any pointers.
Jun 1, 2023, 12:20 AM
Hi
user T
. When you customize your desk structure , there’s the
S
prop as well as a
context
prop. Under
context
is
currentUser
(among other things), which will give you
name
,
roles
,
email
, etc.
Jun 1, 2023, 1:49 AM
user A
Thank you so much. 🎉
Jun 1, 2023, 3:09 PM
Worked like a charm.
Jun 1, 2023, 4:46 PM
Oh yay, I hadn't thought to explore context yet and was looking for something like that last night.
Jun 22, 2023, 7:58 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?