0
I’m trying to make the functionality of login
in the Nodejs
, for this I created a method get
who receives the email
and the password as Query String
and performs a query in the database (MySQL
) checking if there is any ID
with this data, however, the request is awaiting eternally and nothing happens :(
I’ve tried everything and I can’t solve the problem.
Follow my current code
File functions accessing the database
async login(req,res) {
let query = `select id from gerente where email = '${req.query.email}' and senha = '${req.query.senha}'`;
await connection.query(query,(error,results,fields)=> {
if(!error) {
res.json(results)
}
})
}
Path file that executes the function
routes.get('/api/colaboradores/login', colaboradoresController.login);
Note: I use express. Variable names and the connection to the database are correct because I execute other requests of the type get
, post
, put
and delete
and are functioning normally.
Could you tell us the value of
error
and if it is not null can also informerror.sqlMessage
– Augusto Vasques
I put an Else to print the error value, and it does not print anything, just loading infinitely rsrs. I use Insomnia to do the tests
– Vitor Cordeiro
You need to use the
verb
correct that is thepost
, and in the decision-making structure needs to have theelse
to capture the error and also need to go debugging line by line, the problem is local has no way to reproduce– novic
Why post? The correct would be get no? I need to get the id value returned
– Vitor Cordeiro
Just out of curiosity you raised the Mysql server?
– Augusto Vasques
of course! the mysql server is working. I can perform all other functions (delete,put,post and other gets) normally
– Vitor Cordeiro
In the case ai the correct post is a login, if you can not traffic this information so no. super wrong.
– novic