mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 08:53:13 +00:00
45564b0a8a
Fold the 1497-line services/authService.ts into the DI-native nest/auth
domain (Wave-5 chain opener, unblocked by the atlas fold):
- Pure crypto half (backup-code hash/match/generate, stripUserForClient,
key masking, the import-time DUMMY_PASSWORD_HASH timing equaliser and
avatarDir mkdir — documented parity exceptions) moves verbatim to the
plain module nest/auth/auth.helpers.ts.
- DB half folds into AuthService over DatabaseService + injected
PermissionsService (ex permissions.bridge) + AtlasService (ex
atlas.bridge, deleted on schedule). mfaSetupPending and the per-email
reset throttle stay module-scoped so the bridge and container instances
share them; avatarDir and require('../../../package.json') re-anchor one
directory deeper — with the two injection swaps, the only non-verbatim
lines. Controller-facing method surface unchanged.
- New 8-export auth.bridge.ts for out-of-container consumers: mcp/index.ts
token verification, the journey/notifications/transports registrars'
isDemoUser, and the still-legacy adminService/oidcService/passkeyService.
- 15 domain *.mcp.ts demo guards now inject AuthService (their modules
import AuthModule); atlas.mcp.ts alone stays on the bridge because
AuthService injects AtlasService and the reverse module edge would close
an AuthModule<->AtlasModule cycle (places.mcp precedent). OidcService and
PasskeyEnabledGuard inject AuthService too.
- Tests move with case IDs preserved: authService.test.ts ->
auth.helpers.test.ts, authServiceDb.test.ts -> auth.service.test.ts
(+ AUTH-BR-001..007 bridge delegation, + AUTH-DB-050..088 pinning the
previously untested getAppConfig/login/MFA/reset/admin-settings branches
now under the src/nest coverage gate). auth.e2e converts DI-native (real
bcrypt, real audit rows); oidc.e2e swaps its dead path mock for an
instance spy; websocket/integration suites repoint to bridge/helpers.
Quirks preserved byte-for-byte (0-coord drop in getTravelStats,
un-transactioned registerUser/verifyMfaLogin multi-writes, unguarded
revokeUserSessions in deleteMcpToken, current! assertions in
updateApiKeys) — fixes land separately.
63 lines
2.5 KiB
TypeScript
63 lines
2.5 KiB
TypeScript
import { db } from '../../db/database';
|
|
import { DatabaseService } from '../database/database.service';
|
|
import { PermissionsService } from '../permissions/permissions.service';
|
|
import { AtlasService } from '../atlas/atlas.service';
|
|
import { AuthService } from './auth.service';
|
|
import { User } from '../../types';
|
|
|
|
/**
|
|
* Non-Nest entry point for the auth domain — for code running OUTSIDE the
|
|
* Nest container: the legacy MCP transport (mcp/index.ts token verification),
|
|
* the legacy tool registrars (mcp/tools/journey|notifications|transports), the
|
|
* not-yet-migrated services/adminService, services/oidcService and
|
|
* services/passkeyService, and — as the one in-container exception —
|
|
* atlas.mcp.ts, which cannot inject AuthService without closing an
|
|
* AuthModule↔AtlasModule cycle (AuthService injects AtlasService for
|
|
* getTravelStats; same documented trade-off as places.mcp.ts keeping its
|
|
* assignments.bridge imports).
|
|
*
|
|
* Exports the legacy services/authService names 1:1 so repointing a consumer
|
|
* is an import-path-only diff. Inside the container, inject AuthService
|
|
* instead. Delete exports as their last legacy consumer migrates.
|
|
*
|
|
* stripUserForClient is pure and re-exported straight from auth.helpers.ts;
|
|
* avatarUrl keeps the legacy re-export shape (services/avatarUrl). The
|
|
* pending-MFA and reset-throttle maps are module-scoped in auth.service.ts,
|
|
* so this instance and the container singleton share one copy.
|
|
*
|
|
* Module-level construction is safe: `db` is the reinitialize-proof Proxy onto
|
|
* the shared better-sqlite3 singleton (same pattern as permissions.bridge.ts).
|
|
*/
|
|
const auth = new AuthService(
|
|
new DatabaseService(db),
|
|
new PermissionsService(new DatabaseService(db)),
|
|
new AtlasService(new DatabaseService(db)),
|
|
);
|
|
|
|
export { stripUserForClient } from './auth.helpers';
|
|
export { avatarUrl } from '../../services/avatarUrl';
|
|
|
|
export function isDemoUser(userId: number): boolean {
|
|
return auth.isDemoUser(userId);
|
|
}
|
|
|
|
export function verifyMcpToken(rawToken: string): User | null {
|
|
return auth.verifyMcpToken(rawToken);
|
|
}
|
|
|
|
export function verifyJwtToken(token: string): User | null {
|
|
return auth.verifyJwtToken(token);
|
|
}
|
|
|
|
export function resolveAuthToggles() {
|
|
return auth.resolveAuthToggles();
|
|
}
|
|
|
|
export function generateToken(user: { id: number | bigint; password_version?: number }, rememberMe = false) {
|
|
return auth.generateToken(user, rememberMe);
|
|
}
|
|
|
|
export function createWsToken(userId: number) {
|
|
return auth.createWsToken(userId);
|
|
}
|