How to Get the Information of Current User (For Example Userid)

3 replies
Last updated: Jul 7, 2022
How can I get the information of current user (For example userid) ? Calling a specific api or there might be something in the client object once user logged in ?
Jul 7, 2022, 8:23 AM
That looks like the api for fetching user by the user id. But I have some problem get the current user id who is logged in.
Jul 7, 2022, 8:30 AM
You can use the
to get the current user. Something like:
import userStore from 'part:@sanity/base/user'

async () => {
    const currentUser = await userStore.getCurrentUser()
There are some context where the current user is provided already, like in a
conditional field.
Jul 7, 2022, 4:45 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?