use Current User
The useCurrentUser hook fetches the Shop app user's profile information including display name and avatar image URL. Use this for personalizing the UI, displaying user info in headers/profiles, or conditionally showing features based on authentication status.
Caution
This hook requires adding the following scopes to the manifest file:
user_settings:read
For more details, see manifest.json.
Caution:
This hook requires adding the following scopes to the manifest file:
user_settings:read
For more details, see manifest.json.
Anchor to useCurrentUser-parametersParameters
- Anchor to paramsparamsparamsUseCurrentUserParamsUseCurrentUserParams
UseCurrentUserReturnsUseCurrentUserReturns
UseCurrentUserParams
- fetchPolicy
DataHookFetchPolicy - skip
boolean
DataHookFetchPolicy
'cache-first' | 'network-only'UseCurrentUserReturns
- currentUser
The current user logged into Shop.
UserProfile | null - error
Error | null - loading
boolean - refetch
() => Promise<void>
UserProfile
- avatarImage
{ url: string } | null - displayName
string | null
Examples
tsx
import {useCurrentUser} from '@shopify/shop-minis-react'
export default function MyComponent() {
const {currentUser, loading, error} = useCurrentUser()
if (loading) {
return <p>Loading user...</p>
}
if (error) {
return <p>Unable to load user</p>
}
if (!currentUser) {
return <p>No user found</p>
}
return <p>Hi, {currentUser.displayName}</p>
}
Examples
Example code
tsx
import {useCurrentUser} from '@shopify/shop-minis-react' export default function MyComponent() { const {currentUser, loading, error} = useCurrentUser() if (loading) { return <p>Loading user...</p> } if (error) { return <p>Unable to load user</p> } if (!currentUser) { return <p>No user found</p> } return <p>Hi, {currentUser.displayName}</p> }
Was this page helpful?