Help articles

Warning: userStore.currentUser is deprecated (Studio v2)

This page documents the Studio v2 user store. Both userStore.currentUser and userStore.me were removed in Studio v3, and nothing in current Sanity exposes them. Current Sanity reads the signed-in user with the useCurrentUser() hook instead. Follow this page only if you are still running Studio v2.

The userStore.currentUser observable has been deprecated in favor of userStore.me, which is an observable stream of the current logged-in user or null if the user is logged out.

Where the userStore.currentUser observable stream emitted a snapshot event object with the user object at the user property every time user state changed, the userStore.me emits the user object (or null if logged out) as you would see it from the /users/me API endpoint.

The userStore.currentUser stream could also emit an error event shaped {type: 'error', error}. Because userStore.me has no error variant, move any code that branched on event.type into the error callback you pass to subscribe().

Example of how to migrate existing code currently using userStore.currentUser to instead use userStore.me:

Before

import userStore from 'part:@sanity/base/user'

userStore.currentUser.subscribe(event => {
  console.log('Current user is:', event.user)
})

After

import userStore from 'part:@sanity/base/user'

userStore.me.subscribe(user => {
  console.log('Current user is:', user)
})

Was this page helpful?