mirror of
https://github.com/filecoffee/filehost.git
synced 2024-11-13 19:49:56 +01:00
16 lines
453 B
JavaScript
16 lines
453 B
JavaScript
const bcrypt = require("bcryptjs");
|
|
const User = require("../database/models/user.model");
|
|
|
|
const authenticate = async (req, res, next) => {
|
|
const { username, password } = req.body;
|
|
const user = await User.findOne({ where: { username } });
|
|
|
|
if (user && bcrypt.compareSync(password, user.password)) {
|
|
req.session.userId = user.id;
|
|
next();
|
|
} else {
|
|
res.status(401).send("Authentication failed");
|
|
}
|
|
};
|
|
|
|
module.exports = authenticate;
|