From c36085e5801f991980f871e154e7c22287571692 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sun, 5 Jan 2025 19:37:28 +0100 Subject: [PATCH] chore: fix TS warning by type narrowing `req.csrfToken` might be undefined according to `csrf-csrf` provided types, so use type narrowing to make sure it exists, before calling it --- src/routes/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/index.ts b/src/routes/index.ts index 5115630a0..4a26d8387 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -19,7 +19,7 @@ function index(req: Request, res: Response) { const view = !utils.isElectron() && req.cookies["trilium-device"] === "mobile" ? "mobile" : "desktop"; - const csrfToken = req.csrfToken(); + const csrfToken = (typeof req.csrfToken === "function") ? req.csrfToken() : undefined; log.info(`Generated CSRF token ${csrfToken} with secret ${res.getHeader("set-cookie")}`); // We force the page to not be cached since on mobile the CSRF token can be