useUser is a React hook that retrieves the currently authenticated user’s profile information. It fetches user data from the /auth/profile endpoint and provides loading and error states.
Usage
Signature
Return Value
The hook returns an object with the following properties:The authenticated user object, or
null if not authenticated, or undefined if still loading.See the User type for available properties.true while the user profile is being fetched, false otherwise.An error object if the profile fetch failed, or
null if no error occurred.Function to manually revalidate the user data. Useful for refreshing the profile after updates.
User Type
TheUser object contains standard OIDC profile claims:
The user’s unique identifier.
The user’s full name.
The user’s nickname.
The user’s given/first name.
The user’s family/last name.
URL of the user’s profile picture.
The user’s email address.
Whether the user’s email has been verified.
The organization ID that the user belongs to. This field is populated when the user logs in through an organization.
Configuration
By default, the hook fetches from/auth/profile. You can customize this endpoint using the NEXT_PUBLIC_PROFILE_ROUTE environment variable:
Notes
- The hook uses SWR for data fetching, which provides automatic caching and revalidation
- The user data is shared across all
useUser()calls in your application - You must wrap your application with
<Auth0Provider>to use this hook - The hook makes a client-side fetch request, so it only works in React components