mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 01:11:29 +00:00
28 lines
427 B
JavaScript
28 lines
427 B
JavaScript
const jwt = require('jsonwebtoken');
|
|
|
|
var Auth = function (req, res, next) {
|
|
var token = '';
|
|
try {
|
|
token = req.headers.authorization.substring(7);
|
|
} catch(ex) {
|
|
console.log(ex);
|
|
res.sendStatus(401);
|
|
return;
|
|
}
|
|
|
|
jwt.verify(token, req.key, function(err, decoded) {
|
|
if(err) {
|
|
console.log(err);
|
|
res.sendStatus(401);
|
|
return;
|
|
}
|
|
|
|
req.token = decoded;
|
|
next();
|
|
});
|
|
};
|
|
|
|
module.exports = {
|
|
'auth': Auth
|
|
}
|