Problems passing Query String as parameter in nodejs

Asked

Viewed 386 times

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 inform error.sqlMessage

  • 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

  • You need to use the verb correct that is the post, and in the decision-making structure needs to have the else to capture the error and also need to go debugging line by line, the problem is local has no way to reproduce

  • Why post? The correct would be get no? I need to get the id value returned

  • Just out of curiosity you raised the Mysql server?

  • 1

    of course! the mysql server is working. I can perform all other functions (delete,put,post and other gets) normally

  • In the case ai the correct post is a login, if you can not traffic this information so no. super wrong.

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.