exports.login = async (req, res) => { try { const pool = await poolConnect const result = await pool.request() .input("username", sql.VarChar(50), req.body.username) .execute("procedure-name") .then((data) => { if (data.recordset.length < 1) { return res.status(401).json({ message: 'Denied' }); } bcrypt.compare(req.body.password, data.recordset[0].password, (err, result) => { if (err) { return res.status(401).json({ message: 'Denied' }); } if (result) { const token = jwt.sign( //JWT configuration ); return res.status(200).json({ message: 'successs', token: token }); } res.status(401).json({ message: 'Denied' }); }); }); } catch (err) { res.status(500) res.send(err.message) } };
Обсуждают сегодня