24 lines
683 B
JavaScript
24 lines
683 B
JavaScript
const { Key } = require("../.Key.js");
|
|
|
|
const validateToken = () => {
|
|
return (req, res, next) => {
|
|
const token = req.headers['authorization'];
|
|
|
|
if (!token) {
|
|
console.log("No token provided");
|
|
return res.status(403).send({ message: 'No token provided.' });
|
|
}
|
|
|
|
console.log(`Expected token: ${Key.token}`);
|
|
|
|
if (token === Key.token) {
|
|
console.log("Token valid, calling next()");
|
|
next();
|
|
} else {
|
|
console.log("Unauthorized access attempt");
|
|
return res.status(401).send({ message: 'Unauthorized.' });
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = { validateToken }; |