useSession hook reads session data in server components.
Example codeAnchor link to section titled "Example code"
Return valueAnchor link to section titled "Return value"
useSession hook returns all data within the current session. The return type is an object with key value pairs.
ConsiderationsAnchor link to section titled "Considerations"
You can't use the
useSessionhook 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.
useSessionhook will suspend when its called. The length of the suspense depends on where the session data is stored.