Skip to Content
You are viewing a beta version of Clerk Docs
Visit the latest docs
Clerk logo

Clerk Docs

Ctrl + K
Go to clerk.com

useSession()

The useSession() hook provides access to the current user's Session object, as well as helpers for setting the active session.

useSession() returns

NameTypeDescription
isLoadedbooleanA boolean that is set to false until Clerk loads and initializes.
isSignedInbooleanA boolean that is set to true if the user is signed in.
sessionSessionHolds the current active session for the user.

How to use the useSession() hook

The following example demonstrates how to use the useSession() hook to access the SignIn object, which has the lastActiveAt property on it. The lastActiveAt property is used to display the last active time of the current session to the user.

home.tsx
import { useSession } from "@clerk/clerk-react"; export default function Home() { const { isLoaded, session, isSignedIn } = useSession(); if (!isLoaded) { // Add logic to handle loading state return null; } if(!isSignedIn) { // Add logic to handle not signed in state return null; } return ( <div> <p>This session has been active since {session.lastActiveAt.toLocaleString()} </p> </div> ) }

Last updated on February 22, 2024

What did you think of this content?

Clerk © 2024