Skip to main content

useSessionList()

The useSessionList() hook returns an array of Session objects that have been registered on the client device.

Returns

There are multiple variants of this type available which you can select by clicking on one of the tabs.

  • Name
    isLoaded
    Type
    false
    Description

    Indicates whether Clerk has loaded the current authentication state. Initially false, becomes true once Clerk loads, and can revert to false while auth state is updating (for example, when switching organizations via setActive()).

  • Name
    sessions
    Type
    undefined
    Description

    A list of sessions that have been registered on the client device.

  • Name
    setActive
    Type
    undefined
    Description

    A function that sets the active session and/or Organization. See the reference doc.

  • Name
    isLoaded
    Type
    true
    Description

    Indicates whether Clerk has loaded the current authentication state. Initially false, becomes true once Clerk loads, and can revert to false while auth state is updating (for example, when switching organizations via setActive()).

  • Name
    sessions
    Type
    SessionResource[]
    Description

    A list of sessions that have been registered on the client device.

  • Name
    setActive()
    Type
    (setActiveParams: SetActiveParams) => Promise<void>
    Description

    A function that sets the active session and/or Organization. See the reference doc.

Example

Get a list of sessions

The following example uses useSessionList() to get a list of sessions that have been registered on the client device. The sessions property is used to show the number of times the user has visited the page.

app/routes/index.tsx
import { useSessionList } from '@clerk/tanstack-react-start'
import { createFileRoute } from '@tanstack/react-router'

export const Route = createFileRoute('/')({
  component: Home,
})

export default function Home() {
  const { isLoaded, sessions } = useSessionList()

  // Handle loading state
  if (!isLoaded) return <div>Loading...</div>

  return (
    <div>
      <p>Welcome back. You've been here {sessions.length} times before.</p>
    </div>
  )
}

Feedback

What did you think of this content?

Last updated on