From 877c6e1de1e9c25152b70e1efdbcf8c77e8db19e Mon Sep 17 00:00:00 2001 From: Nicolas Meienberger Date: Mon, 22 Dec 2025 17:10:03 +0100 Subject: [PATCH] chore(app): move auth middleware to individual controller To clean up de main app.ts file --- app/server/app.ts | 6 ------ app/server/modules/backups/backups.controller.ts | 2 ++ app/server/modules/events/events.controller.ts | 3 ++- .../modules/notifications/notifications.controller.ts | 2 ++ app/server/modules/repositories/repositories.controller.ts | 2 ++ app/server/modules/system/system.controller.ts | 2 +- app/server/modules/volumes/volume.controller.ts | 2 ++ 7 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/server/app.ts b/app/server/app.ts index b2d12d02..93ed52ae 100644 --- a/app/server/app.ts +++ b/app/server/app.ts @@ -55,12 +55,6 @@ export const createApp = () => { ) .get("healthcheck", (c) => c.json({ status: "ok" })) .route("/api/v1/auth", authController) - .use("/api/v1/volumes/*", requireAuth) - .use("/api/v1/repositories/*", requireAuth) - .use("/api/v1/backups/*", requireAuth) - .use("/api/v1/notifications/*", requireAuth) - .use("/api/v1/system/*", requireAuth) - .use("/api/v1/events/*", requireAuth) .route("/api/v1/volumes", volumeController) .route("/api/v1/repositories", repositoriesController) .route("/api/v1/backups", backupScheduleController) diff --git a/app/server/modules/backups/backups.controller.ts b/app/server/modules/backups/backups.controller.ts index e9fa9f7a..fefeacb7 100644 --- a/app/server/modules/backups/backups.controller.ts +++ b/app/server/modules/backups/backups.controller.ts @@ -41,8 +41,10 @@ import { type UpdateScheduleNotificationsDto, } from "../notifications/notifications.dto"; import { notificationsService } from "../notifications/notifications.service"; +import { requireAuth } from "../auth/auth.middleware"; export const backupScheduleController = new Hono() + .use(requireAuth) .get("/", listBackupSchedulesDto, async (c) => { const schedules = await backupsService.listSchedules(); diff --git a/app/server/modules/events/events.controller.ts b/app/server/modules/events/events.controller.ts index cd40b845..4661e133 100644 --- a/app/server/modules/events/events.controller.ts +++ b/app/server/modules/events/events.controller.ts @@ -2,8 +2,9 @@ import { Hono } from "hono"; import { streamSSE } from "hono/streaming"; import { logger } from "../../utils/logger"; import { serverEvents } from "../../core/events"; +import { requireAuth } from "../auth/auth.middleware"; -export const eventsController = new Hono().get("/", (c) => { +export const eventsController = new Hono().use(requireAuth).get("/", (c) => { logger.info("Client connected to SSE endpoint"); return streamSSE(c, async (stream) => { diff --git a/app/server/modules/notifications/notifications.controller.ts b/app/server/modules/notifications/notifications.controller.ts index 643d03b7..42a4b0e7 100644 --- a/app/server/modules/notifications/notifications.controller.ts +++ b/app/server/modules/notifications/notifications.controller.ts @@ -17,8 +17,10 @@ import { type UpdateDestinationDto, } from "./notifications.dto"; import { notificationsService } from "./notifications.service"; +import { requireAuth } from "../auth/auth.middleware"; export const notificationsController = new Hono() + .use(requireAuth) .get("/destinations", listDestinationsDto, async (c) => { const destinations = await notificationsService.listDestinations(); return c.json(destinations, 200); diff --git a/app/server/modules/repositories/repositories.controller.ts b/app/server/modules/repositories/repositories.controller.ts index a53a3a29..0023dfa9 100644 --- a/app/server/modules/repositories/repositories.controller.ts +++ b/app/server/modules/repositories/repositories.controller.ts @@ -31,8 +31,10 @@ import { } from "./repositories.dto"; import { repositoriesService } from "./repositories.service"; import { getRcloneRemoteInfo, listRcloneRemotes } from "../../utils/rclone"; +import { requireAuth } from "../auth/auth.middleware"; export const repositoriesController = new Hono() + .use(requireAuth) .get("/", listRepositoriesDto, async (c) => { const repositories = await repositoriesService.listRepositories(); diff --git a/app/server/modules/system/system.controller.ts b/app/server/modules/system/system.controller.ts index 62d7aade..58dbcc05 100644 --- a/app/server/modules/system/system.controller.ts +++ b/app/server/modules/system/system.controller.ts @@ -14,6 +14,7 @@ import { usersTable } from "../../db/schema"; import { eq } from "drizzle-orm"; export const systemController = new Hono() + .use(requireAuth) .get("/info", systemInfoDto, async (c) => { const info = await systemService.getSystemInfo(); @@ -22,7 +23,6 @@ export const systemController = new Hono() .post( "/restic-password", downloadResticPasswordDto, - requireAuth, validator("json", downloadResticPasswordBodySchema), async (c) => { const user = c.get("user"); diff --git a/app/server/modules/volumes/volume.controller.ts b/app/server/modules/volumes/volume.controller.ts index 7c97260d..ccffeb19 100644 --- a/app/server/modules/volumes/volume.controller.ts +++ b/app/server/modules/volumes/volume.controller.ts @@ -24,8 +24,10 @@ import { } from "./volume.dto"; import { volumeService } from "./volume.service"; import { getVolumePath } from "./helpers"; +import { requireAuth } from "../auth/auth.middleware"; export const volumeController = new Hono() + .use(requireAuth) .get("/", listVolumesDto, async (c) => { const volumes = await volumeService.listVolumes();