Overview

useUser is a React hook that provides the user's information and authentication status.

How to Use

Here's an example of how to use it:

tsx

'use client' import { useUser } from '@/components/hooks/use-user' export default function Profile() { const { user, fetchUser } = useUser() // You can re-fetch the user data if needed // useEffect(() => { // fetchUser() // }, []) // Or, you can use the user object directly here // if (user === null) return <p>Please log in to view your profile.</p> return ( <div> {user ? ( <div> <h1>Welcome, {user.name}!</h1> <p>Email: {user.email}</p> </div> ) : ( <p>Please log in to view your profile.</p> )} </div> ) }

Interface

The user interface structure that you can retrieve from the user object:

ts

{ id: string, email: string, name: string | null, roleId: string | null, session: string, sessions: string[] }