---
title: "useSessions"
description: "useSessions, auto-imported in the app: its options, return value and types."
canonical_url: "https://nuxt-backend.dev/docs/reference/api/use-sessions"
---
# useSessions

## Interfaces

### SessionInfo

Defined in: [src/runtime/vue/composables/use-sessions.ts](https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts)

One of the signed-in user's device sessions (mirrors the `listSessions` query).

#### Properties

<table>
<thead>
  <tr>
    <th>
      Property
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Description
    </th>
    
    <th>
      Defined in
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="id">
        
      </a>
      
       <code>
        id
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      -
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts" rel="nofollow">
        src/runtime/vue/composables/use-sessions.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="useragent">
        
      </a>
      
       <code>
        userAgent
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
      
       | <code>
        null
      </code>
    </td>
    
    <td>
      -
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts" rel="nofollow">
        src/runtime/vue/composables/use-sessions.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="createdat">
        
      </a>
      
       <code>
        createdAt
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      When the device signed in, as epoch ms.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts" rel="nofollow">
        src/runtime/vue/composables/use-sessions.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="updatedat">
        
      </a>
      
       <code>
        updatedAt
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      When the session was last extended, as epoch ms.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts" rel="nofollow">
        src/runtime/vue/composables/use-sessions.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="expiresat">
        
      </a>
      
       <code>
        expiresAt
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      When the session stops signing anyone in, as epoch ms.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts" rel="nofollow">
        src/runtime/vue/composables/use-sessions.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="current">
        
      </a>
      
       <code>
        current
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      Whether this is the session this browser is signed in with.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts" rel="nofollow">
        src/runtime/vue/composables/use-sessions.ts
      </a>
    </td>
  </tr>
</tbody>
</table>

---

### SessionsApi

Defined in: [src/runtime/vue/composables/use-sessions.ts](https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts)

The session functions re-exported from your `backend/auth.ts`.

#### Properties

<table>
<thead>
  <tr>
    <th>
      Property
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Defined in
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="listsessions">
        
      </a>
      
       <code>
        listSessions?
      </code>
    </td>
    
    <td>
      <a href="https://docs.convex.dev/api/modules/server#functionreference" rel="nofollow">
        <code>
          FunctionReference
        </code>
      </a>
      
      <<code>
        "query"
      </code>
      
      , <code>
        "public"
      </code>
      
      , <code>
        Record
      </code>
      
      <<code>
        string
      </code>
      
      , <code>
        never
      </code>
      
      >, <a href="#sessioninfo">
        <code>
          SessionInfo
        </code>
      </a>
      
      <span>
        
      </span>
      
       | <code>
        null
      </code>
      
      >
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts" rel="nofollow">
        src/runtime/vue/composables/use-sessions.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="revokesession">
        
      </a>
      
       <code>
        revokeSession?
      </code>
    </td>
    
    <td>
      <a href="https://docs.convex.dev/api/modules/server#functionreference" rel="nofollow">
        <code>
          FunctionReference
        </code>
      </a>
      
      <<code>
        "mutation"
      </code>
      
      , <code>
        "public"
      </code>
      
      , { <code>
        sessionId
      </code>
      
      : <code>
        string
      </code>
      
      ; }, <code>
        null
      </code>
      
      >
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts" rel="nofollow">
        src/runtime/vue/composables/use-sessions.ts
      </a>
    </td>
  </tr>
</tbody>
</table>

---

### UseSessionsOptions

Defined in: [src/runtime/vue/composables/use-sessions.ts](https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts)

#### Properties

<table>
<thead>
  <tr>
    <th>
      Property
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Description
    </th>
    
    <th>
      Defined in
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="api">
        
      </a>
      
       <code>
        api?
      </code>
    </td>
    
    <td>
      <a href="#sessionsapi">
        <code>
          SessionsApi
        </code>
      </a>
    </td>
    
    <td>
      Override the injected <code>
        api.auth
      </code>
      
       namespace.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts" rel="nofollow">
        src/runtime/vue/composables/use-sessions.ts
      </a>
    </td>
  </tr>
</tbody>
</table>

---

### UseSessionsReturn

Defined in: [src/runtime/vue/composables/use-sessions.ts](https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts)

#### Properties

<table>
<thead>
  <tr>
    <th>
      Property
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Description
    </th>
    
    <th>
      Defined in
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="sessions">
        
      </a>
      
       <code>
        sessions
      </code>
    </td>
    
    <td>
      <code>
        ComputedRef
      </code>
      
      <<a href="#sessioninfo">
        <code>
          SessionInfo
        </code>
      </a>
      
      <span>
        
      </span>
      
       | <code>
        undefined
      </code>
      
      >
    </td>
    
    <td>
      Active sessions, live: <code>
        []
      </code>
      
       when signed out, <code>
        undefined
      </code>
      
       until the first read lands (and during SSR) and after a failed read.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts" rel="nofollow">
        src/runtime/vue/composables/use-sessions.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="current-1">
        
      </a>
      
       <code>
        current
      </code>
    </td>
    
    <td>
      <code>
        ComputedRef
      </code>
      
      <<a href="#sessioninfo">
        <code>
          SessionInfo
        </code>
      </a>
      
       | <code>
        undefined
      </code>
      
      >
    </td>
    
    <td>
      The session belonging to this browser, once the list is loaded.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts" rel="nofollow">
        src/runtime/vue/composables/use-sessions.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="isloading">
        
      </a>
      
       <code>
        isLoading
      </code>
    </td>
    
    <td>
      <code>
        ComputedRef
      </code>
      
      <<code>
        boolean
      </code>
      
      >
    </td>
    
    <td>
      <code>
        true
      </code>
      
       until the first read lands (always <code>
        false
      </code>
      
       when signed out).
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts" rel="nofollow">
        src/runtime/vue/composables/use-sessions.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="ispending">
        
      </a>
      
       <code>
        isPending
      </code>
    </td>
    
    <td>
      <code>
        ComputedRef
      </code>
      
      <<code>
        boolean
      </code>
      
      >
    </td>
    
    <td>
      <code>
        true
      </code>
      
       while <code>
        revoke
      </code>
      
       or <code>
        revokeOthers
      </code>
      
       runs.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts" rel="nofollow">
        src/runtime/vue/composables/use-sessions.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="error">
        
      </a>
      
       <code>
        error
      </code>
    </td>
    
    <td>
      <code>
        ComputedRef
      </code>
      
      < | <a href="https://nuxt-backend.dev/docs/reference/api/functions#backenderror">
        <code>
          BackendError
        </code>
      </a>
      
       | <code>
        null
      </code>
      
      >
    </td>
    
    <td>
      Why the last action failed, else why the list could not be read, else <code>
        null
      </code>
      
      . An action clears its own failure when the next one starts, and signing out clears it.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts" rel="nofollow">
        src/runtime/vue/composables/use-sessions.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="revoke">
        
      </a>
      
       <code>
        revoke
      </code>
    </td>
    
    <td>
      (<code>
        id
      </code>
      
      ) => <code>
        Promise
      </code>
      
      <<code>
        void
      </code>
      
      >
    </td>
    
    <td>
      Sign a session out by id. The list updates on its own. Rejects with the failure, which <code>
        error
      </code>
      
       also holds.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts" rel="nofollow">
        src/runtime/vue/composables/use-sessions.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="revokeothers">
        
      </a>
      
       <code>
        revokeOthers
      </code>
    </td>
    
    <td>
      () => <code>
        Promise
      </code>
      
      <<code>
        void
      </code>
      
      >
    </td>
    
    <td>
      Sign out every session except this one. The list updates on its own. Rejects with the failure, which <code>
        error
      </code>
      
       also holds.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts" rel="nofollow">
        src/runtime/vue/composables/use-sessions.ts
      </a>
    </td>
  </tr>
</tbody>
</table>

## Functions

### useSessions()

```ts
function useSessions(options?): UseSessionsReturn;
```

Defined in: [src/runtime/vue/composables/use-sessions.ts](https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts)

Device-session management: list, revoke one, revoke the rest. The list is
a live query over `listSessions` from `backend/auth.ts`, so a session
signed out anywhere drops off without a reload; it works for sessions of
any age (Better Auth's own `/list-sessions` demands a sign-in from the
last day). Rows carry ids, never session tokens. The list never throws: a
failed read shows in `error`. The actions reject on failure and mirror it
into `error`.

#### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        options?
      </code>
    </td>
    
    <td>
      <a href="#usesessionsoptions">
        <code>
          UseSessionsOptions
        </code>
      </a>
    </td>
  </tr>
</tbody>
</table>

#### Returns

[`UseSessionsReturn`](#usesessionsreturn)

#### Example

```vue
<script setup lang="ts">
const { sessions, revoke, isPending, error } = useSessions()
</script>
<template>
  <p v-if="error">{{ error.message }}</p>
  <ul>
    <li v-for="session in sessions" :key="session.id">
      {{ describeUserAgent(session.userAgent) ?? 'Unknown device' }}
      <button v-if="!session.current" :disabled="isPending" @click="revoke(session.id)">Sign out</button>
    </li>
  </ul>
</template>
```

---

### describeUserAgent()

```ts
function describeUserAgent(userAgent?): string | null;
```

Defined in: [src/runtime/vue/composables/use-sessions.ts](https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-sessions.ts)

A short label for a session's device, `Chrome · macOS` style, from its
user agent. `null` when there is no user agent or nothing in it is
recognisable, so the page shows its own wording for an unknown device.

#### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        userAgent?
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
      
       | <code>
        null
      </code>
    </td>
  </tr>
</tbody>
</table>

#### Returns

`string` | `null`


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
