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