useSession
The useSession
hook reads session data in server components.
Example code
Anchor link to section titled "Example code"
Return value
Anchor link to section titled "Return value"The useSession
hook returns all data within the current session. The return type is an object with key value pairs.
Considerations
Anchor link to section titled "Considerations"You can't use the
useSession
hook in client components. If your client components need access to session data, then get the data within server components and explicitly pass the data to client components.Don't update session data within server or client components. Instead, update session data within API routes.
The
useSession
hook will suspend when its called. The length of the suspense depends on where the session data is stored.