expressServer/utils/loginUtil.js
LingandRX 87ea20acd0 feat(utils): 添加登录验证中间件
- 新增 authenticateSession 函数用于验证用户登录状态
- 该中间件将用于保护需要登录才能访问的路由
2024-12-24 23:17:57 +08:00

8 lines
178 B
JavaScript

exports.authenticateSession = async (req, res, next) => {
if (req.session.user) {
next()
} else {
res.status(401).json({ error: 'Unauthorized' })
}
}