From 909daf885348d4598c31b121afdd90934a9e4b14 Mon Sep 17 00:00:00 2001 From: saravanakumardb1 Date: Thu, 5 Mar 2026 11:18:27 -0800 Subject: [PATCH] fix(diagnostics): getAuthToken throws when no token (type-safe), void .start(), unsyncedCount replaces conflictCount --- backend/src/modules/timers/routes.ts | 4 ++-- web/src/lib/diagnostics.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/backend/src/modules/timers/routes.ts b/backend/src/modules/timers/routes.ts index 80085dc..160bacd 100644 --- a/backend/src/modules/timers/routes.ts +++ b/backend/src/modules/timers/routes.ts @@ -150,7 +150,7 @@ export async function timerRoutes(app: FastifyInstance) { const active = timers.filter(t => t.state === 'active' || t.state === 'warning').length; const pending = timers.filter(t => t.state === 'paused').length; const lastSyncedAt = timers[0]?.lastSyncedAt ?? null; - const conflictCount = timers.filter(t => t.syncVersion === 0).length; + const unsyncedCount = timers.filter(t => t.lastSyncedAt == null).length; return { userId: auth.sub, @@ -158,7 +158,7 @@ export async function timerRoutes(app: FastifyInstance) { totalTimers: timers.length, active, pending, - conflictCount, + unsyncedCount, lastSyncedAt, generatedAt: new Date().toISOString(), }; diff --git a/web/src/lib/diagnostics.ts b/web/src/lib/diagnostics.ts index 5e58865..17ae1cb 100644 --- a/web/src/lib/diagnostics.ts +++ b/web/src/lib/diagnostics.ts @@ -31,12 +31,17 @@ export function initDiagnostics(): void { buildNumber: process.env.NEXT_PUBLIC_BUILD_NUMBER ?? '1', releaseChannel: process.env.NEXT_PUBLIC_RELEASE_CHANNEL ?? 'beta', serverUrl: getBaseUrl(), - getAuthToken: () => getAuthClient().getAccessToken() ?? undefined, + getAuthToken: () => { + const token = getAuthClient().getAccessToken(); + if (!token) throw new Error('unauthenticated'); + return token; + }, captureConsole: true, captureErrors: true, captureNetwork: false, pollIntervalMs: 30_000, - }).start(); + }); + void DiagnosticsClient.getInstance().start(); } export function stopDiagnostics(): void {