Ride-The-Lightning-RTL/routes/authCheck.js
2019-02-12 08:36:04 -05:00

15 lines
362 B
JavaScript

const jwt = require("jsonwebtoken");
module.exports = (req, res, next) => {
try {
const token = req.headers.authorization.split(" ")[1];
jwt.verify(token, "default_secret_key");
next();
} catch (error) {
res.status(401).json({
message: "Authentication Failed!",
error: "Authentication Failed! Please Login First!"
});
}
};