---
title: "Show who is here"
description: "Keep the signed-in person in a room while a page is open, and list who else is there, live: Convex's presence component behind the backend's sign-in, and useRoomPresence."
canonical_url: "https://nuxt-backend.dev/docs/build/data/read-write/presence"
---
# Show who is here

> Keep the signed-in person in a room while a page is open, and list who else is there, live: Convex's presence component behind the backend's sign-in, and useRoomPresence.

Version: nuxt-backend 0.6.x · Tab: Build · Kind: how-to · Status: experimental

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

- [API reference](https://nuxt-backend.dev/docs/reference/api/presence)
- [Source](https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/presence.ts)

A room is whatever the app names: a document, a page, a workspace. While a page is open and visible, each person on it sends a heartbeat, and everyone in the room sees who else is there as people come and go, without a message per heartbeat. Convex's [presence component](https://www.convex.dev/components/presence) keeps the rooms. The package puts them behind the backend's sign-in: a heartbeat counts the signed-in account, never an id the browser names, and the room can refuse an account. `useRoomPresence` runs it from a page. It is experimental ([Stability](https://nuxt-backend.dev/docs/ship/releases/stability)).

## Install and mount the component

```bash
pnpm add @convex-dev/presence
```

```ts [backend/convex.config.ts]
import presence from '@convex-dev/presence/convex.config'

// …the scaffold's mounts
app.use(presence)
```

`npx nuxt-backend doctor` reports the mount missing once a backend file imports `setupPresence`, and `--fix` adds it.

## Export the presence functions

```ts [backend/presence.ts]
import { setupPresence } from 'nuxt-backend/presence'
import { components } from './_generated/api'

export const { list, heartbeat, disconnect } = setupPresence(components)
```

Every signed-in account may join every room by default. Name who may join with `canJoin`, which runs on each heartbeat with the room, the account and its identity claims; a refusal answers `forbidden` with reason `presence_room`:

```ts [backend/presence.ts]
export const { list, heartbeat, disconnect } = setupPresence(components, {
  // A workspace's room lets in the members of that workspace only.
  canJoin: ({ roomId, claims }) => !roomId.startsWith('workspace:') || roomId === `workspace:${claims.activeOrganizationId}`,
})
```

`list` answers by the room token a heartbeat handed back, to a signed-in caller who is still in that room, so only someone the room let in reads who else is in it. `canJoin` runs on heartbeats only: it lets people in, and a refused heartbeat leaves someone already in the room there, still able to read it with the room's token. So the mutation that takes access away, such as removing a member from a workspace, also calls `presence.removeRoomUser` from the setup's `presence` client, in the same transaction; `list` then refuses them (`forbidden`, reason `presence_room`) until a heartbeat lets them in again. Each person comes with their name and picture, when the account has them. A room lists at most 50 people (`limit`, up to 200). An administrator acting as someone else sends no heartbeat (`forbidden`, reason `impersonating`): the room never shows the account they visit as present.

## Show who is here on a page

```vue [pages/docs/[id].vue]
<script setup lang="ts">
const route = useRoute()
const { members, others } = useRoomPresence(() => `doc:${route.params.id}`)
</script>

<template>
  <p v-if="others.length">
    {{ others.map(person => person.name ?? 'Someone').join(', ') }} also here
  </p>
  <FacePile :presence-state="members ?? []" />
</template>
```

`members` is everyone in the room, the signed-in person first, and `undefined` while it loads; `others` is who else is online now. Signed out, the composable sends nothing and lists nobody; it joins once someone signs in, and leaves when they sign out. A tab that is hidden leaves the room and joins again when it shows; one that closes leaves at once. `<FacePile>` is the base module's avatar row, registered once `@convex-dev/presence` is installed.

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Default
    </th>
    
    <th>
      
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        interval
      </code>
    </td>
    
    <td>
      <code>
        10000
      </code>
    </td>
    
    <td>
      Milliseconds between heartbeats. Someone who leaves without a word drops off after two and a half of them. The server holds it between one second and five minutes.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        api
      </code>
    </td>
    
    <td>
      <code>
        api.presence
      </code>
    </td>
    
    <td>
      The functions to call, when they live elsewhere.
    </td>
  </tr>
</tbody>
</table>

## Rooms of your own

`setupPresence(…).presence` is the component's own client, for the app's functions: `listRoom` to read a room from a query, `removeRoomUser` and `removeRoom` to clear one. These check no sign-in: call them from functions that do.

## Related

- [Protect backend functions](https://nuxt-backend.dev/docs/build/auth/access/functions): the tiers to check a room by, in `canJoin` and in your own room functions.
- [Scope tables to a workspace](https://nuxt-backend.dev/docs/build/data/read-write/workspace-scoped): the active workspace a workspace room checks.
- [Query and update data](https://nuxt-backend.dev/docs/build/data/read-write): the live queries the room list is built on.
- [`nuxt-backend/presence`](https://nuxt-backend.dev/docs/reference/api/presence): the API reference, with `useRoomPresence` in [Composables](https://nuxt-backend.dev/docs/reference/nuxt/composables).


## Sitemap

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