feat: Initial commit of PDF Tools project

This commit is contained in:
2025-08-25 02:29:48 +08:00
parent af6827cd9e
commit 30180e50a2
48 changed files with 36364 additions and 1 deletions

42
server/middleware/auth.js Normal file
View File

@@ -0,0 +1,42 @@
const jwt = require('jsonwebtoken');
const auth = (req, res, next) => {
try {
const token = req.header('Authorization')?.replace('Bearer ', '');
if (!token) {
return res.status(401).json({
success: false,
message: '未提供访问令牌'
});
}
const decoded = jwt.verify(token, process.env.JWT_SECRET);
req.user = decoded;
next();
} catch (error) {
res.status(401).json({
success: false,
message: '无效的访问令牌'
});
}
};
// 可选身份验证中间件
const optionalAuth = (req, res, next) => {
try {
const token = req.header('Authorization')?.replace('Bearer ', '');
if (token) {
const decoded = jwt.verify(token, process.env.JWT_SECRET);
req.user = decoded;
}
next();
} catch (error) {
// 忽略错误,继续执行
next();
}
};
module.exports = { auth, optionalAuth };