middleware check authenticate

This commit is contained in:
Nikola Petrov
2023-10-04 20:16:47 +02:00
parent e3279d4792
commit ea623cedc8
9 changed files with 34 additions and 63 deletions

View File

@@ -0,0 +1,19 @@
var UserModel = require('../models/userModel');
async function checkAuthenticated(req, res, next) {
try{
const password = req.body.pass;
const userFound = await UserModel.findOne({ pass: password });
if (!userFound) {
return res.status(404).json({ message: 'Wrong password' });
}
req.user = userFound;
return next();
}catch (err) {
console.log(err);
return res.status(500).json({ message: 'Error when getting transactions.' });
}
}
module.exports = checkAuthenticated;