import { UseUserReturn } from "../../types/hooks.mjs"; //#region src/react/hooks/useUser.d.ts /** * The `useUser()` hook provides access to the current user's [`User`](https://clerk.com/docs/reference/objects/user) object, which contains all the data for a single user in your application and provides methods to manage their account. This hook also allows you to check if the user is signed in and if Clerk has loaded. * * @unionReturnHeadings * ["Loading", "Signed out", "Signed in"] * * @example * ### Get the current user * * The following example uses the `useUser()` hook to access the [`User`](https://clerk.com/docs/reference/objects/user) object, which contains the current user's data such as their full name. The `isLoaded` and `isSignedIn` properties are used to handle the loading state and to check if the user is signed in, respectively. * * ```tsx {{ filename: 'src/Example.tsx' }} * import { useUser } from '@clerk/react' * * export default function Example() { * const { isSignedIn, user, isLoaded } = useUser() * * if (!isLoaded) { * return
Loading...
* } * * if (!isSignedIn) { * return
Sign in to view this page
* } * * return
Hello {user.firstName}!
* } * ``` * * @example * ### Update user data * * The following example uses the `useUser()` hook to access the [`User`](https://clerk.com/docs/reference/objects/user) object, which calls the [`update()`](https://clerk.com/docs/reference/objects/user#update) method to update the current user's information. * * * * * ```tsx {{ filename: 'src/Home.tsx' }} * import { useUser } from '@clerk/react' * * export default function Home() { * const { isSignedIn, isLoaded, user } = useUser() * * if (!isLoaded) { * // Handle loading state * return null * } * * if (!isSignedIn) return null * * const updateUser = async () => { * await user.update({ * firstName: 'John', * lastName: 'Doe', * }) * } * * return ( * <> * *

user.firstName: {user.firstName}

*

user.lastName: {user.lastName}

* * ) * } * ``` *
* * * ```tsx {{ filename: 'app/page.tsx' }} * 'use client'; * * import { useUser } from '@clerk/nextjs'; * * export default function HomePage() { * const { isSignedIn, isLoaded, user } = useUser(); * * if (!isLoaded) { * // Handle loading state * return null; * } * * if (!isSignedIn) return null; * * const updateUser = async () => { * await user.update({ * firstName: 'John', * lastName: 'Doe', * }); * }; * * return ( * <> * *

user.firstName: {user.firstName}

*

user.lastName: {user.lastName}

* * ); * } * ``` * *
*
* * @example * ### Reload user data * * The following example uses the `useUser()` hook to access the [`User`](https://clerk.com/docs/reference/objects/user) object, which calls the [`reload()`](https://clerk.com/docs/reference/objects/user#reload) method to get the latest user's information. * * * * * ```tsx {{ filename: 'src/Home.tsx' }} * import { useUser } from '@clerk/react' * * export default function Home() { * const { isSignedIn, isLoaded, user } = useUser(); * * if (!isLoaded) { * // Handle loading state * return null; * } * * if (!isSignedIn) return null; * * const updateUser = async () => { * // Update data via an API endpoint * const updateMetadata = await fetch('/api/updateMetadata', { * method: 'POST', * body: JSON.stringify({ * role: 'admin' * }) * }); * * // Check if the update was successful * if ((await updateMetadata.json()).message !== 'success') { * throw new Error('Error updating'); * } * * // If the update was successful, reload the user data * await user.reload(); * }; * * return ( * <> * *

user role: {user.publicMetadata.role}

* * ); * } * ``` * *
* * * ```tsx {{ filename: 'app/page.tsx' }} * 'use client'; * * import { useUser } from '@clerk/nextjs'; * * export default function HomePage() { * const { isSignedIn, isLoaded, user } = useUser(); * * if (!isLoaded) { * // Handle loading state * return null; * } * * if (!isSignedIn) return null; * * const updateUser = async () => { * // Update data via an API endpoint * const updateMetadata = await fetch('/api/updateMetadata', { * method: 'POST', * body: JSON.stringify({ * role: 'admin', * }), * }); * * // Check if the update was successful * if ((await updateMetadata.json()).message !== 'success') { * throw new Error('Error updating'); * } * * // If the update was successful, reload the user data * await user.reload(); * }; * * return ( * <> * *

user role: {user.publicMetadata.role}

* * ); * } * ``` * *
*
*/ declare function useUser(): UseUserReturn; //#endregion export { useUser }; //# sourceMappingURL=useUser.d.mts.map