11 lines
329 B
JavaScript
11 lines
329 B
JavaScript
// 简单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();
|
||
};
|