# Récit account

A Récit account is optional. Writing, building, presenting, exporting, driving a deck over local
Wi-Fi, and running AI jobs with your own API key all work without an account and without a server.

**The hosted service is not online yet.** Account commands and backend routes are outside the 1.0
contract ([Stability](/documentation/reference/stability)).

## What the account opens

Signing in only opens online services on top of the local tools:

- **Account sign-in, sessions, and personal tokens** — **available** in `@recit/cli` (`recit login`,
  `recit whoami`, `recit logout`) and in the private `@recit/api` HTTP service (GitHub, Google, and
  ProConnect OAuth 2.0 / OpenID Connect with PKCE, email and password, RFC 8628 device
  authorization, central connection for product sites, session listing and revocation, and `rct_`
  personal access tokens). The browser pages are **available** in the private account application
  (`apps/account`, built on the [application mode](/documentation/configuration/application-mode) of
  the site framework): sign-in, sign-up, forgotten password, email verification, device confirmation
  (`/device`), and one settings page (profile, sessions, sign-in methods, personal tokens, remote
  rooms, the name and logo of the organizations you own or administer, your data). The name and the
  logo change through `PATCH /v1/organizations/:organizationId`, for an owner or an admin only; the
  logo is an `https` address of an image, emptied to remove it. An owner also deletes an
  organization there, its name retyped, through `DELETE /v1/organizations/:organizationId`; a
  subscription in progress, an invoice, a paid order or a project billed through Stripe keeps it,
  and every reason is listed. The same page shows the journal of each organization you own or
  administer (`GET /v1/organizations/:organizationId/activity`): what changed and who changed it,
  from its members to its projects, collections and sites, each action in words in English or
  French. Its public address is **planned**.
- **Authenticated site collections** — **available** in `@recit/data-store/client` (`writeDocument`
  and `deleteDocument`) and `@recit/api` for organization members and invited site managers (see
  [Published collections](/documentation/reference/published-collections#writing-with-an-account)).
- **AI through Récit's server** — **planned** on `@recit/api` (only `GET /v1/ai/quota`, the use of
  the account's quota, is **available**): server-hosted [AI jobs](/documentation/plugins/ai) with
  per-account quotas so prompts and provider keys stay on the server.
  `serverProvider({ url, token })` from `@recit/ai` and `createAiServer` from `@recit/ai/server` are
  **available** for plugin authors running their own server.
- **Licenses and paid plugins** — **partly available**. `@recit/api` checks organization product
  entitlements (`GET /v1/products/:productId/organizations/:organizationId/access`) and lists the
  licences of an account (`GET /v1/licenses`), both **available**. One licence is read by
  `GET /v1/licenses/:productId` (the whole product) and `GET /v1/licenses/:productId/:resourceId`
  (one plugin of it), `404` when the account holds none: the private registry of a paid plugin asks
  it before serving the archive
  ([Publishing a plugin](/documentation/plugins/publishing#selling-a-plugin)), **available**.
  [Récit Studio](/documentation/integrations/studio) reads that list with its session for a feature
  that has a price, and keeps the feature open when it cannot read it (no account, the server out of
  reach, a refused session); today no feature of Studio has a price. Payment through Stripe is
  **available** in `@recit/api`: an owner or an admin opens the payment page of an offer its product
  declares (`POST /v1/organizations/:organizationId/billing/checkout`, `503` when the server has no
  Stripe key), and Stripe's signed webhook (`POST /v1/billing/stripe/webhook`) grants the
  entitlement on payment and closes it at the end of a subscription, each event applied once.
  Selling an offer is **planned**, and payment never blocks local builds or offline work.
- **Phone remote outside the local network** — **available** in `@recit/api`, as a preview: a hosted
  WebSocket relay (`/v1/relay`) so a signed-in presenter pairs a phone over the Internet with a QR
  code (the phone needs no account). A room is opened from
  [Récit Studio](/documentation/integrations/studio) or from the settings page of the account, which
  shows its keys once, lists the open rooms and closes them (`GET`, `POST /v1/relay/rooms`,
  `DELETE /v1/relay/rooms/:roomId`, `404` for anyone but its owner). Récit Remote joins the room by
  the QR code; a phone without it lands on the account's `/remote` page, which says how to open the
  code. Single-use ticket URLs (`getTicket`) and jittered exponential backoff
  (`relayReconnectDelay`) in `@recit/deck`'s `PresentationPeerMessenger` serve both.
- **Synchronization, real-time collaboration, and private decks** — **planned** only if a concrete
  need appears later, with no scheduled implementation. Syncing stories across machines uses your
  own tools (such as git or a synced folder), and static sites can add a browser password modal
  without a server ([Protect a site with a password](/documentation/configuration/password)).

## What works without an account

You never need an account to use Récit locally, and **no feature breaks when the server is down**:

- **Write, build, and present** stories in Markdown or typed JSON from the CLI (`recit init`,
  `recit dev`, `recit build`, `recit validate`) or
  [Récit Studio](/documentation/integrations/studio). A project is a plain folder on disk.
- **Export** stories to PDF, standalone HTML, PowerPoint, or images (`recit export`), and render
  motion films or webtoon episodes to MP4 (`recit render`).
- **Control a deck on the same Wi-Fi network** with `recit dev --remote` or Studio's local relay
  ([Smartphone remote](/formats/deck/smartphone-remote)).
- **Run AI jobs with your own key** (`anthropic`, `openai`, or `gemini`) directly from your machine
  to the provider ([AI jobs](/documentation/plugins/ai#your-key)).
- **Read published collections** from static `/collections/<name>.json` files; when a server is
  configured and unreachable, `@recit/data-store/client` falls back to those static files
  ([Published collections](/documentation/reference/published-collections)).

## Signing in from the command line

`recit login`, `recit whoami`, and `recit logout` are loaded on demand so no other CLI command
imports account code or reads a token. See [CLI](/documentation/reference/cli) for their options.

```bash
npx recit login
npx recit whoami
npx recit logout
```

- **`recit login`** starts an RFC 8628 device authorization flow (`POST /auth/device/code` with
  `client_id: "recit-cli"`). It prints the verification URL and a short `XXXX-XXXX` code without
  opening a browser, then polls `POST /auth/device/token` every `5` seconds (`slow_down` adds `5`
  seconds; the code expires after `10` minutes). Once approved, the session token is written to
  `credentials.json` in your Récit config folder (`$XDG_CONFIG_HOME/recit`, `~/.config/recit`, or
  `%APPDATA%\recit` on Windows) with `0700` folder and `0600` file permissions on POSIX systems.
  This session is of kind `cli`: it can read your account and your content, but it cannot create
  personal access tokens, list or revoke devices and sessions, link a sign-in provider, or delete
  the account (`403`); do these from the browser. The API routes `GET /v1/device`,
  `POST /v1/device/approve`, and `POST /v1/device/deny` are **available**; the browser confirmation
  page at `/device` is **planned**.
- **`recit whoami`** queries `GET /v1/me` and prints the signed-in user and where the token came
  from (`RECIT_TOKEN` or `credentials.json`). Pass `--json` for machine-readable output.
- **`recit logout`** revokes the saved session on the server (`POST /auth/logout`) when reachable
  and deletes its entry from `credentials.json`, even offline. It never revokes or clears
  `RECIT_TOKEN`.
- **`RECIT_TOKEN`** sets a bearer token in the environment — such as an `rct_` personal access token
  in CI — and takes precedence over `credentials.json`.
- **`RECIT_API_URL`** points `recit login`, `recit logout`, and `recit whoami` at another Récit
  service URL (`--api-url` overrides it). `https://` is required except on `localhost`, `127.0.0.1`,
  and `[::1]`; URLs carrying credentials, a query string, or a fragment are refused.

## Central connection

Product sites served on separate domains do not share cookies with the central account host.
Instead, a product site obtains its own session through a PKCE (`S256`) authorization-code exchange
on `@recit/api` (`Cache-Control: no-store`; `GET /auth/connect` is rate-limited to `60` requests per
`15` minutes per client IP, and `POST /auth/connect/token` is rate-limited per
`(product, client IP)` pair to `600` requests per minute and `60` `invalid_grant` failures per `15`
minutes, and per client IP to `300` `invalid_grant` failures per `15` minutes):

1. **Browser redirect (`GET /auth/connect`).** The product site redirects the browser to
   `/auth/connect?product=<id>&redirect_uri=<url>&state=<state>&code_challenge=<digest>&code_challenge_method=S256`
   (`state` is `1` to `512` printable ASCII characters without spaces). `product` must be an active
   registered product and `redirect_uri` must be `https://<its domain>/auth/callback` on one of that
   product's declared domains, with no port, credentials, query string, or fragment; any invalid
   parameter or untrusted `redirect_uri` returns `400` (`{ "error": "invalid_request" }`) in JSON
   and never redirects.
2. **One-time callback (`302`, `Referrer-Policy: no-referrer`).** Only an active `auth_session`
   cookie of kind `web` whose sign-in method is allowed for the product counts as signed in (`cli`
   or `product` cookies and `Authorization: Bearer` headers count as unsigned-in). Without one, it
   sends the browser to the sign-in page of the account (`/connect` on the account application, with
   the same query), which signs the person in and comes back to `/auth/connect` with `prompt=none`.
   With `prompt=none`, or when the session was opened by a method outside the product's `signIn`
   list, `/auth/connect` issues no code and redirects to
   `https://<its domain>/auth/callback?error=login_required&state=<state>`; a product that never
   wants the sign-in page sends `prompt=none` itself. With one, it stores only the SHA-256 digest of
   a one-time code valid for `60` seconds and redirects to
   `https://<its domain>/auth/callback?code=<code>&state=<state>` so no session token ever appears
   in a URL.
3. **Server-to-server exchange (`POST /auth/connect/token`).** The product's server posts
   `{ "product", "code", "code_verifier", "redirect_uri" }` (no cookie read, no CORS headers) to
   consume the code once and receive `200` (`{ "token", "expiresAt", "userId" }`) for an opaque
   session of kind `product` bound to that product (`400` with `invalid_request` on a malformed
   body, or `invalid_grant` if the code is unknown, expired, already used, or fails PKCE
   verification).
4. **Rotation (`POST /auth/connect/refresh`).** A product that keeps its session on the user's
   machine, such as Récit Studio, sends it as `Authorization: Bearer <token>` (no body, no cookie)
   before it expires and receives `200` (`{ "token", "expiresAt", "userId" }`): a new session of the
   same product and family, valid for another `30` days, while the presented token stops working. A
   web session, an unknown or expired token answers `401`; a token presented again after its
   rotation is treated as stolen and revokes every session of its family. The route is rate-limited
   per client IP (`30` per minute).

- **Allowed sign-in methods (`signIn`).** A product's `signIn` list (`"github"`, `"google"`,
  `"password"`, `"proconnect"`) chooses the methods that open a session on that product, not only
  what its sign-in screen displays. Central `web` sessions record the method that opened them
  (`signInMethod`), and `/auth/connect` redirects with `error=login_required` without issuing a code
  whenever that method is absent from the product's `signIn` list (sessions created without a
  recorded `signInMethod` still pass; the password sign-up, sign-in, and forgot-password routes also
  return `404` when given a `product` whose `signIn` list omits `"password"`). ProConnect — the
  identity provider for public-sector agents — is offered only by a product that declares
  `"proconnect"` in `signIn` (the default list is `"github"`, `"google"`, and `"password"`). A Récit
  account that already has that email address is never linked silently: sign in first, then link
  ProConnect from the account page.
- **Scope of a `product` session.** A session is valid for every product of the account: a `product`
  session opened by one product calls the routes of any product
  (`/v1/products/:productId/organizations/:organizationId/…`, whatever `:productId`), with the same
  organization and entitlement checks as a web session (`404` outside them). It also reads the
  signed-in account (`GET /v1/me`), signs itself out (`POST /auth/logout`) and calls the routes open
  to every session (licences, render jobs, relay rooms, the AI quota and jobs). The account's own
  routes — `PATCH /v1/me`, `DELETE /v1/me`, the export, organization routes outside
  `/v1/products/:productId/…`, sessions, personal tokens, devices, and OAuth linking — refuse a
  `product` session with `403` (`{ "error": "forbidden" }`). When a product is deactivated (absent
  or no longer `active` in `core.products`), its `product` sessions cease to be valid:
  `requireSession` rejects them with `401` like an invalid session, including on `GET /v1/me`, while
  `web` and `cli` sessions are unaffected.
- **Signing out (`POST /auth/logout`).** Signing out with a `product` session revokes only that
  session family and clears `auth_session`. Signing out with a `web` or `cli` session revokes that
  session family and every non-revoked `product` session of the user in the same transaction
  (recording `details: { productSessionsRevoked }` on the `sign_out` audit entry).

## Sessions and personal tokens

The settings page of the account application lists and revokes both; `@recit/api` exposes the HTTP
routes below.

### Sessions

- **Opaque tokens.** A session token is 32 random bytes encoded in hexadecimal, never a JWT.
  PostgreSQL stores only its SHA-256 hex digest (`tokenHash`). Sessions expire after 30 days by
  default.
- **Transport and CSRF check.** Requests authenticate with the `auth_session` cookie
  (`HttpOnly; Secure; SameSite=Lax; Path=/`) or `Authorization: Bearer <token>`. State-changing
  cookie requests (`POST`, `PUT`, `PATCH`, `DELETE`) require an `Origin` header matching the
  configured application origin (`403` otherwise).
- **Revocation.** An expired or revoked token gets `401`. `GET /v1/sessions` lists active sessions
  (marking `current: true` and omitting `tokenHash`), `DELETE /v1/sessions/:id` revokes a session
  family (`404` when unknown, already revoked, or owned by another user), and `POST /auth/logout`
  revokes the caller's session family and clears `auth_session`.
- **Rotation.** A product session rotates through `POST /auth/connect/refresh`
  ([Central connection](#central-connection)): the old token gives a new one of the same family, and
  an already-rotated token that comes back revokes the whole family (`401`). A web session does not
  rotate; it expires or is revoked.

### Personal tokens

- **Prefix and one-time display.** Personal access tokens start with `rct_` followed by 32 random
  hex-encoded bytes. `POST /v1/tokens` (`201`, `Cache-Control: no-store`) returns the raw `rct_…`
  token once and stores only its SHA-256 digest (`tokenHash`).
- **Name, scopes, and 365-day cap.** Creating a token requires a non-empty `name` (at most 100
  characters), 1 to 32 unique `scopes` matching `^[a-z][a-z0-9_]*(:[a-z][a-z0-9_]*)*$` (up to 64
  characters each), and a future `expiresAt` timestamp at most **365 days** ahead. The account page
  offers five scopes (`PERSONAL_TOKEN_SCOPES` of `@recit/platform-api/shared`) and checks the first
  by default: `account:read`, the profile that `recit whoami` reads, `licenses:read`, the licences
  of the account, for a CI job that installs a paid plugin, `agents:report`, the token of the
  agents' machine, which reports its agents and takes their orders, for an administrator only,
  `render:write`, to queue the render jobs of the connector, and `ai:run`, to run the AI jobs of the
  service, counted in your quota and billable to an organization.
- **Listing, revocation, and scope boundaries.** `GET /v1/tokens` lists active tokens (`id`, `name`,
  `scopes`, `expiresAt`, `lastUsedAt`, `createdAt`, never `token` or `tokenHash`) and
  `DELETE /v1/tokens/:tokenId` revokes one immediately (`204`, or `404` when unknown, already
  revoked, or owned by another user). Some routes of `@recit/api` accept
  `Authorization: Bearer rct_…`: `GET /v1/me` and `GET /v1/ai/quota` with any scope, so
  `recit whoami` works in CI, `GET /v1/licenses` only with `licenses:read` and `/v1/render/jobs`
  only with `render:write` and `POST /v1/jobs/<job>` only with `ai:run` (`401` otherwise). Every
  other authenticated route (organizations, sites, the management of forms) requires a session and
  answers `401` to an `rct_` token. Two kinds of route stand apart: the public ones need no token at
  all (`/healthz`, `/auth/*`, reading a public collection and its `/events`, `POST` of a structure
  counter, `POST /v1/forms/:resourceId`), and the pilot routes of collections that write or list a
  structure's data take that structure's own token, not an `rct_` one.
- **Renders.** The account page lists the render jobs of the connector under « Renders »
  (`GET /v1/render/jobs`, the most recent first): each with its format and file, its state (waiting,
  rendering, ready or failed), when it was sent, and the size of its file or why it failed; the file
  itself is fetched by the tool that asked for it.

## Your data

Self-service export and erasure are **available**: the routes of `@recit/api`, and the « Your data »
section of the account page that calls them:

- **Export (`GET /v1/me/export`).** Requires an `auth_session` cookie (rejects `Bearer` tokens with
  `401`) and is rate-limited per client IP (`10` requests per hour by default). Downloads a JSON
  attachment (`recit-account-export.json`, `format: "recit-account-export"`, `version: 1`,
  `Cache-Control: no-store`) gathering personal data across `core` (profile, organization
  memberships, linked OAuth providers, roles, sessions, personal token metadata, devices,
  invitations, contacts, audit entries) and every mounted module that holds some, each under its id
  in `data.sources`: `ai` (the AI jobs of the account, never their text), `collections` (site
  manager grants and the invitations received), `forms` (the form submissions whose `email` field is
  the account's address), `mail` (the mail subscriptions of that address), `relay` (the open rooms
  of the remote relay), `render` (the most recent render jobs, without the story of a job still
  waiting) and `sites` (the orders placed with that address on a Récit Sites shop, never Stripe
  identifiers) — never password hashes or token digests.
- **Account deletion (`DELETE /v1/me`).** Requires an `auth_session` cookie, a matching `Origin`
  header, and `{ "confirm": "<email>" }` matching the account's email (`400 confirmation_required`
  otherwise). In a single transaction, it deletes sole-member organizations owned by the caller
  (returning `409 sole_owner` if the caller is the sole active owner of a multi-member
  organization), deletes sessions, personal tokens, device codes, devices, memberships, OAuth links,
  roles, verifications, and invitations, anonymizes the user record, pseudonymizes its audit entries
  (they keep the now anonymous user id, so an organization's activity shows "Deleted User"; the IP
  is truncated to its /24 or /48, the user agent is removed, and the details keep only identifiers
  and closed values, never free text), erases the personal data of each module: `ai` (deletes the AI
  jobs of the account), `collections` (deletes the site manager invitations received, deletes or
  clears those it sent, deletes its manager grants and clears it from the grants it gave), `forms`
  (deletes the form submissions whose `email` field is the account's address), `mail` (deletes the
  mail subscriptions of that address), `relay` (deletes the rooms of the remote relay), `render`
  (deletes the render jobs) and `sites` (anonymizes the orders placed with that address), and clears
  `auth_session` (`204`).
- **Story content.** Decks and stories stay in your local folders. The account service keeps the
  JSON of a story you send to render only while its job waits or runs, then clears it.
