# Device sessions

Everywhere you're signed in, with how each session signed in (browser, device code, or a token from the environment), where, and when it was last used. Sign out one, or all but this one.

- Registry name: `device-sessions` (`@candor/device-sessions`)
- Tier: Pro. Installing it needs a Pro, Premium or Team licence key: the person runs `npx candor-ui key <key>` themselves; never ask for the key in chat or write it to a file.
- Docs: https://candor.themethodic.com/docs/device-sessions

## Install

```bash
npx candor-ui add device-sessions
```

Run `npx candor-ui@latest init` once first (https://candor.themethodic.com/get-started.md). Without the CLI: `npx shadcn@latest add @candor/device-sessions`.
It brings in: button, locale, ops, relative-time, utils.
npm packages: lucide-react@^1.67.0.

## Example

```tsx
"use client"

import * as React from "react"
import { DeviceSessions } from "@/components/device-sessions"
import type { DeviceSession } from "@/lib/ops"

const ago = (m: number) => new Date(Date.now() - m * 60_000).toISOString()

export default function Example() {
  const [sessions, setSessions] = React.useState<DeviceSession[]>([
    { id: "d1", device: "Chrome on macOS", method: "browser", location: "Boston, US", signedInAt: ago(60 * 24 * 3), lastActiveAt: ago(0), current: true },
    { id: "d2", device: "keel CLI on dev laptop", method: "device", location: "Boston, US", signedInAt: ago(60 * 24 * 9), lastActiveAt: ago(60 * 5) },
    { id: "d3", device: "CI: release pipeline", method: "environment", signedInAt: ago(60 * 24 * 20), lastActiveAt: ago(60 * 26) },
  ])
  return (
    <DeviceSessions
      className="max-w-xl"
      sessions={sessions}
      onSignOut={(id) => setSessions((s) => s.filter((x) => x.id !== id))}
      onSignOutOthers={() => setSessions((s) => s.filter((x) => x.current))}
    />
  )
}
```

## <DeviceSessions>

Props:

- `sessions: DeviceSession[]`: Every signed-in session, including the current one.
- `onSignOut?: ((id: string) => void) | undefined`: Shows Sign out on each other session; called with its id.
- `onSignOutOthers?: (() => void) | undefined`: Shows a button to sign out every session but this one, when there are others.
- `className?: string | undefined`

## Strings (`deviceSessions`)

The fixed words, English by default. Override any of them under `deviceSessions` in `<LocaleProvider strings={{ deviceSessions: { … } }}>`; the table is exported as `deviceSessionsStrings`.

- `label`: Signed-in sessions
- `heading`: Where you’re signed in
- `signOutOthers`: { one: "Sign out {count} other session", other: "Sign out {count} other sessions" }
- `thisSession`: This session
- `methodBrowser`: Browser sign-in
- `methodDevice`: Device code (CLI)
- `methodEnvironment`: Token from environment
- `activeNow`: active now
- `lastUsed`: last used {when}
- `signOut`: Sign out
- `signOutDevice`: Sign out {device}

## Rules for using Candor UI

- Components take plain typed data. Never pass model output as HTML or render it as a link; messages are typed blocks.
- A control that can't be used says why: wrap it in `<Locked reason="…">`, don't just disable it.
- Don't show a value you don't have: leave it out (it renders as —) rather than guess. An estimate is labelled as one.
- Nothing is pre-selected in a decision a person makes, and the agent is named from your app's data, never from model output.
- Your app's words go in `LocaleProvider` (fixed strings) and `TermsProvider` (nouns); entity kinds and agent roles in `EntityKindsProvider` and `AgentRolesProvider`.
