Created
January 24, 2020 15:41
-
-
Save AshutoshSajan/eba6c59ca877e75a0b94b681ba0b2548 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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