Files
multy-stub/server/routers/back-new/middleware/auth.js
2025-07-03 13:28:29 +00:00

11 lines
329 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 简单token认证中间件支持token-3格式
module.exports = function (req, res, next) {
const auth = req.headers.authorization;
if (auth && auth.startsWith('Bearer token-')) {
const id = parseInt(auth.replace('Bearer token-', ''));
if (!isNaN(id)) {
req.user = { id };
}
}
next();
};