mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 05:26:47 +00:00
9aab9e7513
A session token was a signed JWT and nothing else. Logout only cleared the cookie, a 30-day "remember me" token stayed valid wherever a copy of it had ended up, and nobody could sign out one device short of changing the password or rotating the JWT secret for everyone. Every session token now carries an id (jti) naming a row in the new user_sessions table (id, user_id, created_at, last_seen_at, expires_at, revoked_at, user_agent cut to 256 characters; no address is kept). The rows live behind UserSessionsRepository and the new sessions domain, whose SessionsService is the one issuer: AuthService.generateToken and the OIDC sign-in both go through it, and sliding renewal re-signs a tracked token under the same id and moves its expiry. verifyJwtAndLoadUser takes the repository and refuses a token whose session is revoked, expired or gone, refreshing last_seen_at at most every five minutes. A token without a jti was issued before this change; it passes until its own expiry (or a password change), so the upgrade signs nobody out, and renewal turns it into a tracked session. Sessions end on logout (the one the request names, verified even when expired), on a password change (all, the device gets a new one), a password reset, an admin setting a password, reset-admin.js, an MFA disable (all but the current one), an admin clearing a user's MFA, and with the account. GET /api/auth/sessions lists the active sessions, DELETE /api/auth/sessions/:id ends one and POST /api/auth/sessions/revoke-others ends all but the current, with their contracts in @trek/shared and two new audit actions. There is no UI for them yet. MCP exposes no account or session tools, so there is no parallel tool to change; an MCP call made with a session JWT as bearer goes through the same check. The token in the login, register, demo-login, MFA and passkey bodies stays for API clients but is marked deprecated in the API docs and in the client type, which never read it. A nightly session-purge job on CronRegistrarService deletes the expired and revoked rows. The migration is 042500. The sessions domain gets its own coverage entry at the 80 floor until a full run measures it.
111 lines
4.6 KiB
TypeScript
111 lines
4.6 KiB
TypeScript
/**
|
|
* @trek/shared — single source of truth for TREK's API contracts.
|
|
*
|
|
* Zod schemas defined here are consumed by BOTH the server (validation +
|
|
* inferred DTO types) and the client (typed requests/responses). A route is
|
|
* only considered "migrated" once its contract lives in this package.
|
|
*
|
|
* Layout: one folder per domain (e.g. src/trip/trip.schema.ts), plus the
|
|
* domain-agnostic primitives below. See the board card "Module blueprint".
|
|
*/
|
|
export * from './common/primitives.schema';
|
|
export * from './common/pagination.schema';
|
|
|
|
// Domain contracts
|
|
export * from './weather/weather.schema';
|
|
export * from './public-api/public-api.schema';
|
|
export * from './airport/airport.schema';
|
|
export * from './config/config.schema';
|
|
export * from './system-notice/system-notice.schema';
|
|
export * from './maps/maps.schema';
|
|
export * from './maps/place-shadow.schema';
|
|
export * from './maps/route-usage.schema';
|
|
export * from './category/category.schema';
|
|
export * from './tag/tag.schema';
|
|
export * from './notification/notification.schema';
|
|
export * from './memories/memories.schema';
|
|
export * from './atlas/atlas.schema';
|
|
export * from './vacay/vacay.schema';
|
|
export * from './packing/packing.schema';
|
|
export * from './packing/packed-count';
|
|
export * from './todo/todo.schema';
|
|
export * from './budget/budget.schema';
|
|
export * from './budget/receipt-scan.schema';
|
|
export * from './reservation/reservation.schema';
|
|
export * from './reservation/ki-reservation.schema';
|
|
export * from './datetime/datetime-normalize';
|
|
export * from './airtrail/airtrail.schema';
|
|
export * from './dawarich/dawarich.schema';
|
|
export * from './docsync/docsync.schema';
|
|
export * from './day/day.schema';
|
|
export * from './day/note-colors';
|
|
export * from './day/chrono-order';
|
|
export * from './day/stay-bookends';
|
|
export * from './assignment/assignment.schema';
|
|
export * from './place/place.schema';
|
|
export * from './place/place-match';
|
|
export * from './place/place-website';
|
|
export * from './roadtrip/roadtrip.schema';
|
|
export * from './place/track-colors';
|
|
export * from './tours/tours.schema';
|
|
export * from './tours/tours.metrics';
|
|
export * from './geo/haversine';
|
|
export * from './collection/collection.schema';
|
|
export * from './collection/collection-file.schema';
|
|
export * from './trip/trip.schema';
|
|
export * from './place/place-hours';
|
|
export * from './trip/day-grid';
|
|
export * from './trip-invite/trip-invite.schema';
|
|
export * from './collab/collab.schema';
|
|
export * from './file/file.schema';
|
|
export * from './journey/journey.schema';
|
|
export * from './book/book.schema';
|
|
export * from './book/journey-stats.schema';
|
|
export * from './book/book-store.schema';
|
|
export * from './share/share.schema';
|
|
export * from './storage/storage.schema';
|
|
export * from './settings/settings.schema';
|
|
export * from './appearance/appearance.schema';
|
|
export * from './backup/backup.schema';
|
|
export * from './auth/auth.schema';
|
|
export * from './auth/password-policy';
|
|
export * from './sessions/sessions.schema';
|
|
export * from './oidc/oidc.schema';
|
|
export * from './oauth/oauth.schema';
|
|
export * from './admin/admin.schema';
|
|
|
|
// Realtime WS event contract registry (event names + payload schemas)
|
|
export * from './realtime/events.schema';
|
|
export * from './roadtrip/day-boundary.schema';
|
|
|
|
// Sanitisation helpers — used by the client today, scoped here so the server
|
|
// has them ready if rich-text input ever ships.
|
|
export * from './sanitize/sanitize';
|
|
|
|
// WGS-84 ⇄ GCJ-02. Shared because the two boundaries that need it sit on
|
|
// opposite sides: the Amap provider on the server, the Leaflet CRS on the client.
|
|
export * from './geo/gcj02';
|
|
|
|
// i18n registry (language list + pure helpers — no locale data)
|
|
export * from './i18n/languages';
|
|
export * from './i18n/plural';
|
|
|
|
// Plugin permission list, generated from the host's protocol/envelope.ts
|
|
// (server/scripts/gen-plugin-facts.ts). The admin consent screens render from it.
|
|
export * from './plugin-permissions';
|
|
// Plugin settings contracts: the settings-field descriptor + admin instance-config wire shapes.
|
|
export * from './plugins/plugins.schema';
|
|
// Plugin POI categories (#1781): the declared category, the icon allow-list and GET /api/plugin-pois.
|
|
export * from './plugins/plugin-poi-facts';
|
|
export * from './plugins/plugin-poi.schema';
|
|
// Plugin search providers (#2221): the row GET /api/plugin-search and its typed-ahead twin answer with.
|
|
export * from './plugins/plugin-search.schema';
|
|
export * from './roadtrip/preferences.schema';
|
|
export * from './roadtrip/hazards.schema';
|
|
export * from './roadtrip/planning.schema';
|
|
export * from './roadtrip/search.schema';
|
|
export * from './roadtrip/google-import.schema';
|
|
export * from './roadtrip/charging.schema';
|
|
|
|
export * from './vacay/school-holiday-catalog.schema';
|