Files
TREK/server/src/typings/express.d.ts
T
Maurice 724c88c201 style: format server and shared with prettier
A mechanical prettier --write over server/src, server/tests, server/scripts
and shared/src with the workspaces' .prettierrc; nothing but layout and
import order changes, and every file keeps the same set of imports. shared
is formatted throughout and its format baseline is empty. The server
baseline keeps the 35 files that Prettier would grow past their lint:size
limit (they need a split first, which is not a formatting change), and the
generated entity files stay as their generator writes them.
2026-10-10 21:23:37 +02:00

32 lines
1.3 KiB
TypeScript

// Augments Express's `Request` with the fields TREK middleware + Nest guards
// attach after authentication. Replaces the per-site casts
// (`(req as AuthRequest).user`, `getRequest<Request & { user?: User }>()`) with
// a single source of truth so downstream code can read `req.user` directly.
import type { User } from '../types';
import type { PublicApiGrant } from '@trek/shared';
declare module 'express-serve-static-core' {
interface Request {
/**
* Set by `authenticate` middleware (Express) and `JwtAuthGuard` (Nest).
* Present on every route mounted behind those guards. `null` is used by
* `optionalAuthenticate` to signal "checked, but unauthenticated".
*/
user?: User | null;
/**
* What the `/api/v1` integration key presented on this request may read.
* Set by `ApiTokenGuard`, and only there.
*
* Its own field rather than something folded into `user`: the grant belongs
* to the credential, not to the person, and a cookie session has no grant at
* all. Putting it on `user` would leak a token's restrictions into every
* other auth path that happens to read the same object.
*/
apiToken?: PublicApiGrant;
}
}
// This file has imports, so TS treats it as a module. The empty export keeps
// the `declare module` augmentation visible project-wide.
export {};