app.post('/login', urlencodedParser, async(req, res) => {
let username = req.body.username;
let password = req.body.password;
console.log('before await');
const [row] = await dbConnection.query( // Здесь мы запрашиваем данные, существует ли введенный пользователем логин или нет.
"SELECT * FROM `users` WHERE `name` = ? AND `password` = ?", [username], [password]
);
if (row.length > 0) {
// Authenticate the user
req.session.loggedin = true;
req.session.username = username;
// Redirect to home page
res.send(`Вы вошли под именем ${username}`);
res.end()
} else {
res.send('Неправильный пароль или имя пользователя');
}
});
/home/nikita/galaxy-of-hearing/node_modules/mysql2/promise.js:341
const localErr = new Error();
^
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1
at PromisePool.query (/home/nikita/galaxy-of-hearing/node_modules/mysql2/promise.js:341:22)
at /home/nikita/galaxy-of-hearing/index.js:85:38
at Layer.handle [as handle_request] (/home/nikita/galaxy-of-hearing/node_modules/express/lib/router/layer.js:95:5)
at next (/home/nikita/galaxy-of-hearing/node_modules/express/lib/router/route.js:144:13)
at urlencodedParser (/home/nikita/galaxy-of-hearing/node_modules/body-parser/lib/types/urlencoded.js:82:7)
at Layer.handle [as handle_request] (/home/nikita/galaxy-of-hearing/node_modules/express/lib/router/layer.js:95:5)
at next (/home/nikita/galaxy-of-hearing/node_modules/express/lib/router/route.js:144:13)
at Route.dispatch (/home/nikita/galaxy-of-hearing/node_modules/express/lib/router/route.js:114:3)
at Layer.handle [as handle_request] (/home/nikita/galaxy-of-hearing/node_modules/express/lib/router/layer.js:95:5)
at /home/nikita/galaxy-of-hearing/node_modules/express/lib/router/index.js:284:15 {
code: 'ER_PARSE_ERROR',
errno: 1064,
sql: "SELECT * FROM `users` WHERE `name`='root' AND password = ?",
sqlState: '42000',
sqlMessage: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1"
}