diff --git a/server/src/middleware/verifyStatusPageAccess.ts b/server/src/middleware/verifyStatusPageAccess.ts new file mode 100644 index 000000000..4b1627b0a --- /dev/null +++ b/server/src/middleware/verifyStatusPageAccess.ts @@ -0,0 +1,18 @@ +import { NextFunction, Request, Response } from "express"; +import { IStatusPagesRepository } from "@/repositories/index.js"; + +export const createVerifyStatusPageAccess = (statusPagesRepository: IStatusPagesRepository) => { + return async (req: Request, res: Response, next: NextFunction) => { + try { + const url = req.params.url; + const statusPage = await statusPagesRepository.findByUrl(url); + if (statusPage.isPublished) { + next(); // Published — proceed to controller (no JWT) + } else { + next("route"); // Unpublished — skip to next route (which has verifyJWT) + } + } catch (error) { + next(error); + } + }; +};