Skip to content

Instantly share code, notes, and snippets.

@AshutoshSajan
Created January 24, 2020 15:41
Show Gist options
  • Save AshutoshSajan/eba6c59ca877e75a0b94b681ba0b2548 to your computer and use it in GitHub Desktop.
Save AshutoshSajan/eba6c59ca877e75a0b94b681ba0b2548 to your computer and use it in GitHub Desktop.
function verifyToken (req, res, next) {
var token = req.headers.Authorization || req.headers.authorization || "";
if (!token) {
res.status(401).json({
success: false,
message: "please authenticate."
});
} else if (token) {
jwt.verify(token, process.env.JWT_SECRET, (err, decoded) => {
if (err) {
res.status(500).json({
success: false,
message: "server error",
error: err
});
} else if (decoded) {
req.user = decoded;
next();
}
});
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment