personal_website/middleware/checkAuthenticated.js
Nikola Petrov 63346de8c1 Format
2023-10-04 20:19:16 +02:00

19 lines
517 B
JavaScript

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;