chore(app): move auth middleware to individual controller
To clean up de main app.ts file
This commit is contained in:
parent
1ce1e65271
commit
877c6e1de1
7 changed files with 11 additions and 8 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
|
|
@ -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<ListDestinationsDto>(destinations, 200);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue