-2
Good afternoon friends!
I created a Rest api based on a youtube video using Node, express and sequelize. When sending an empty post, for one of the routes without access to the bank, I get return normally.
But when sending a post to create database entries, sequelize uses my PC user credentials, not the user data I entered into the code.
gives me the error: Access denied for user 'degrossoli'@'localhost'
- Route: http://localhost:3030/create
- Json content:
{
"username": "marcos",
"password": 123
}
On the controller I have
async create(req, res) {
const response = { ...responseModel };
const { username, password } = req.body;
const [, affectRows] = await connection.query(`
INSERT INTO users VALUES (
DEFAULT,
'${username}',
'${password}',
NOW(),
NOW()
);
`)
response.success = affectRows > 0;
return res.json(response);
},
My Connection
const Sequelize = require('sequelize');
const database = process.env.DATABASE;
const username = process.env.USERNAME;
const password = process.env.PASSWORD;
const host = process.env.HOST;
const dialect = "mysql";
const connection = new Sequelize(database, username, password, {
host,
dialect
})
module.exports = connection;
All content is in: https://github.com/Marcosed1979/api-com-express
Thank you very much!