# Kundenportal

> konto's reference customer portal in React and Tailwind: sign-in with a passkey or the operator's login, the accounts of every company, the bill that recomputes itself, sharing, payment and delivery. Serve it, theme it, check it.

The Kundenportal answers a customer's questions in the order they ask them: what is open
and by when, with which company and how it is paid; what changed against the last bill;
what happened on the account. A holder also shares the account, grants a SEPA mandate and
chooses e-mail or post. It is a React 19 application, styled with Tailwind 4 on mako's
design tokens, as the other open-utility-stack screens are. You can see its bill on the
[start page](../) and all of it in the sandbox (`just portal`).

## Run it

```sh
just portal            # builds web/ and the recompute module, starts the sandbox
```

The sandbox prints an invitation link, a second company's invitation code and a read-only
token link. Its demo login (`/demo-login`) plays the operator's provider, so „Weiter mit
Demo-Login“ runs the whole provider sign-in offline. To work on the screens with hot
reload, run the sandbox and, in `web/`, `npm run dev`: Vite proxies `/v1` to it. Passkeys
are bound to the sandbox's origin, so sign in on `http://localhost:8080/portal/` and use the dev server with a `#token=` link.

## Serve it

`npm run build` in `web/` writes `web/dist/`: `index.html`, `demo.html` and hashed files
under `assets/`. Serve them from the sign-in origin (`KONTO_SIGNIN_ORIGIN`) next to
kontod's `/v1`, for example behind your reverse proxy, with the recompute module beside
`index.html`:

```text
https://kunden.stadtwerke-musterstadt.de/          → web/dist/index.html
https://kunden.stadtwerke-musterstadt.de/assets/…  → web/dist/assets/
https://kunden.stadtwerke-musterstadt.de/konto_wasm.wasm
https://kunden.stadtwerke-musterstadt.de/v1/…      → kontod
```

The build needs no inline script or style. Send at least this policy:

```text
Content-Security-Policy: default-src 'self'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self';
  img-src 'self' data: blob:; connect-src 'self'; frame-ancestors 'none'; base-uri 'none';
  form-action 'none'
```

The portal reads kontod as the signed-in customer: the session is an HttpOnly cookie no
script can read. With `#token=…&account=…` it reads one account with a token of the role
`portal` instead, as an operator's backend does; it then changes nothing.

## What it shows

| Screen | Does |
|---|---|
| Anmelden | „Weiter mit {Login}“ first where the operator's login is configured, then „Mit Passkey anmelden“; with an invitation code or an `#invitation=` link (which leaves the address bar at once) it connects the login or sets up a passkey; a refused or cancelled return shows its German message |
| Ihre Konten | every account at every company, grouped by company: what is open, when, how it is paid; adds another company's invitation ([several companies](several-creditors.md)) |
| Ihr Konto | what is open, the last bill, „Was hat sich geändert?“ and the Verlauf; a bill in the Verlauf opens beside it |
| Rechnung | amount and due date first, „Rechnung nachrechnen“ in the browser, PDF and e-invoice, sections and totals |
| Bezahlen, Rechnungen erhalten | for the holder: a SEPA mandate under its text, or transfer; e-mail with consent, or post ([payment and delivery](self-service.md)) |
| Zugang teilen | for the holder: share read-only until a date, see who has access, revoke ([sign-in](sign-in.md)) |

A browser without passkeys sees a German note instead of a button that cannot work, and
the operator's login where there is one. The
JSON forms of WebAuthn (`PublicKeyCredential.parseCreationOptionsFromJSON`, `toJSON()`)
are in Chrome 129, Safari 18 and Firefox 119 and later.

## Theme

Colours, surfaces, status, focus and motion are mako's tokens
(`web/src/design/mako-tokens.css`, copied verbatim; `npm run drift` reports when mako's
change). Every colour is a `light-dark()` pair, so the portal follows the system's
appearance, and more contrast and reduced motion are honoured. konto adds a customer's
reading size in `web/src/design/tokens.css`. Your brand is the one accent:

```css
:root { --accent: light-dark(#c4161c, #ff8a82); }
```

## Built to be checked

`npm run check` in `web/` (and `just web`) runs:

- the types (TypeScript, strict) and Biome;
- the guards: no `dangerouslySetInnerHTML`, `innerHTML`, `eval` or `new Function` in the
  source, every dependency at an exact version, nothing at run time beyond React;
- Vitest with Testing Library: money and dates, markup shown as text, the account list;
- the build and its budget: the portal's JavaScript and CSS under 96 KB gzipped (about
  80 KB, most of it React);
- the drift from mako's tokens.

`just portal-check` runs every flow in Chromium against the sandbox with Playwright: a
virtual authenticator as the customer's phone, the sandbox's Content-Security-Policy, axe
at WCAG 2.2 AA on every screen, and no console error.
