uLicense/uLicense-1.2.6/dashboard/middleware/auth.js
2022-09-15 03:43:05 +01:00

22 lines
497 B
JavaScript

const jwt = require('jsonwebtoken');
const auth = (req, res, next) => {
try {
const token = req.header('Authorization');
if (!token)
return res.status(400).json({ msg: 'Invalid Authentication.' });
jwt.verify(token, process.env.ACCESS_TOKEN_SECRET, (err, user) => {
if (err)
return res.status(400).json({ msg: 'Invalid Authentication.' });
req.user = user;
next();
});
} catch (err) {
return res.status(500).json({ msg: err.message });
}
};
module.exports = auth;