Skip to content

refactor(backend): remove (app as any).authenticate fallback chains from remaining route files #594

@yachikadev

Description

@yachikadev

Summary

Remove the unsafe (app as any).authenticate fallback chains still present in cards.ts, event.ts, nfc.ts, and connect.ts, and replace them with the typed app.authenticate decorator — same pattern just applied to team.ts in #581 (closes #554).

Contexts

In #581, team.ts was refactored to remove all any usages and replace the manual auth fallback chain with a properly typed app.authenticate decorator (typed via the @fastify/jwt + Fastify augmentation in src/types/fastify.d.ts).

The same unsafe pattern still exists in several other route files:

if (typeof (app as any).authenticate === 'function') {
  await (app as any).authenticate(request, reply);
  return;
}

and in a few places, an additional request.server as any fallback layered on top. This was flagged as a follow-up during review on #581 so the cleanup can go repo-wide instead of being one-off.

Tasks

  • Replace (app as any).authenticate / request.server as any fallback chains with preHandler: [app.authenticate] in src/routes/cards.ts
  • Same cleanup in src/routes/event.ts
  • Same cleanup in src/routes/nfc.ts
  • Same cleanup in src/routes/connect.ts
  • Remove the now-redundant manual request.jwtVerify() try/catch in each preHandler (the decorator already handles 401 on failure)
  • Update corresponding test files so app.authenticate is decorated inside buildApp() before app.register(...) (Fastify resolves preHandler during app.ready())

Acceptance Criteria

  • No (app as any) or request.server as any remains in the 4 files above
  • All routes use preHandler: [app.authenticate] consistently, no .bind(app) needed
  • tsc --noEmit passes with 0 errors
  • ESLint clean on all touched files
  • Existing test suites for these route files pass (only setup/decorator wiring should change, not test expectations)

Area

backend

Difficulty

Easy / Good first issue — pattern is already established and proven in #581, mostly mechanical repetition across 4 files.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

Status
Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions