Simeon Griggs
π¦πΊ in π¬π§ Solution Engineer @ Sanity
Simeon is located at Newcastle upon Tyne, UK
Get details of the currently logged in Sanity user
import userStore from 'part:@sanity/base/user'
import { useEffect, useState } from 'react'
export function useCurrentUser() {
const [user, setUser] = useState()
useEffect(() => {
userStore.currentUser.subscribe(e => setUser(e.user))
}, [])
if (!user) {
return {}
}
return user
}
Sometimes you want to gate or modify your custom Studio components based on the current logged in user.
This Custom Hook can be dropped into any component to get the user's ID, email address, and more.
π¦πΊ in π¬π§ Solution Engineer @ Sanity
Not all Unpublished Documents are created equal
Go to GROQ Query for new and unpublished Documents