integration of authentication

This commit is contained in:
2024-08-06 17:44:09 +02:00
parent d38817f4c5
commit e7a78dcaad
21 changed files with 526 additions and 127 deletions
+25
View File
@@ -0,0 +1,25 @@
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 };