first commit

This commit is contained in:
2026-01-26 10:54:31 +03:30
commit 1db3038221
20 changed files with 4026 additions and 0 deletions

27
lib/jwtUtils.js Normal file
View File

@@ -0,0 +1,27 @@
const jwt = require("jsonwebtoken");
const generateToken = (userId) => {
const token = jwt.sign({ userId }, "[)51k:7W71Ki+^p:;XxE4LQ£-I@B49", {
expiresIn: "7d",
});
return token;
};
const verifyToken = (req, res, next) => {
const token = req.headers.authorization;
if (!token) {
return res.status(401).json({ message: "Unauthorized: Token missing" });
}
jwt.verify(token, "[)51k:7W71Ki+^p:;XxE4LQ£-I@B49", (err, decoded) => {
if (err) {
return res.status(401).json({ message: "Unauthorized: Invalid token" });
}
req.userId = decoded.userId;
next();
});
};
module.exports = { generateToken, verifyToken };