created(auth) auth middleware has been added and used on person route

This commit is contained in:
Yusuf İpek
2021-07-24 11:04:58 +03:00
parent 84b60d6fb3
commit 2de9d3594a
5 changed files with 216 additions and 8 deletions
+13
View File
@@ -0,0 +1,13 @@
const jwt = require("jsonwebtoken");
module.exports = function auth(req, res, next) {
const token = req.header("x-auth-token");
if (!token) return res.status(401).send("Access denied! No token provided.");
try {
jwt.verify(token, process.env.rememberMe_jwtKey);
next();
} catch (ex) {
return res.status(400).send("Invalid token.");
}
};