Files
artcraft-services/frontend/libs/api
Dylan M. Taylor 63059c2475 fix: keep the session until logout is confirmed by the server (#273)
## What was wrong
- `UsersApi.Logout` in `@storyteller/api` cleared the stored signed
session *before* sending `POST /v1/logout`. That stored value is what
`buildSessionHeaders` sends as the `session` header when third-party
cookies are blocked, so in the cookie-free flow the logout request
carried no credential: the server could not find the session to revoke,
yet the client went on as if logged out. The copied session stayed
valid.
- The moderator dashboard's `NavUser.handleLogout` ignored the `Logout`
result and always called `logoutState()`, so a failed request showed the
login page while the session cookie still worked.

## What changed
- `UsersApi.Logout` sends the request first and clears the stored
session in `.finally()`, so the local credential is still removed
whatever the outcome. It also passes the server's `error_message`
through.
- The dashboard only clears its auth state when logout succeeds. On
failure it shows a toast saying the session is still active, with a
Retry action.

## Blast radius
- All `@storyteller/api` `Logout()` callers (webapp top bar, pagescene
adapter, genhub): the request now carries the session header; local
clearing is unchanged apart from happening after the response.
- Dashboard: on a failed logout the moderator stays signed in and sees
an error, instead of a misleading login page.

## Checks run
- `npx vitest run src/lib/UsersApi.spec.ts` in `libs/api`: 2/2 pass; the
header test fails on `main`. (The spec stubs `localStorage` because Node
26 shadows jsdom's; the existing `MediaFilesApi.spec.ts` fails here for
that reason.)
- Dashboard: `pnpm install --frozen-lockfile`, `tsc -p tsconfig.app.json
--noEmit` clean, `eslint src/components/nav-user.tsx` clean.

## Checks not run
- Logout against a running API in cookie-free (header) mode.
- Manual dashboard logout with the API unreachable.

Addresses CodeRabbit security findings (CWE-613).
2026-11-11 11:11:26 -05:00
..
2026-06-14 22:20:29 -04:00

api

This library was generated with Nx.

Building

Run nx build api to build the library.

Running unit tests

Run nx test api to execute the unit tests via Vitest.