From 87ea20acd0c64506927645374bb9494ad427fd40 Mon Sep 17 00:00:00 2001 From: LingandRX <56020800+LingandRX@users.noreply.github.com> Date: Tue, 24 Dec 2024 23:17:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(utils):=20=E6=B7=BB=E5=8A=A0=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=AA=8C=E8=AF=81=E4=B8=AD=E9=97=B4=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 authenticateSession 函数用于验证用户登录状态 - 该中间件将用于保护需要登录才能访问的路由 --- utils/loginUtil.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 utils/loginUtil.js diff --git a/utils/loginUtil.js b/utils/loginUtil.js new file mode 100644 index 0000000..acff66e --- /dev/null +++ b/utils/loginUtil.js @@ -0,0 +1,8 @@ +exports.authenticateSession = async (req, res, next) => { + if (req.session.user) { + next() + } else { + res.status(401).json({ error: 'Unauthorized' }) + } + } + \ No newline at end of file