title: Variable doesn't get set in connection query [Node.js, MySQL]
body: <p>I am having an issue with the session variable not setting. I am assuming the problem has something to do with the functions being asynchronous(async/await).</p>
  <p>How do I make sure that session is set before jwt.sign and committing (how should I use async await or promises here)?</p>
  <pre><code>connection.getConnection(function(err, conn) {
      try {
          conn.beginTransaction(function(err) {
              if (err) { 
                  throw err
              }
              conn.query(`INSERT INTO USER SET username = ?, email = ?; SELECT LAST_INSERT_ID() AS id;`, [username, hashedEmail], (error, results) =&gt; {
                  if(error){
                      throw error;
                  } else {
                      // this doesn't set
                      req.session.verify = results[0].id;
                      jwt.sign(
                          {},
                          process.env.gmail_secret,
                          {
                              expiresIn: '1d',
                          },
                          (err, emailToken) =&gt; {
                              //...
                          }
                      )
  
                      await conn.commit(async function(error) {
                          if (error) {
                              throw err;
                          }
                          await conn.destroy();
                          req.flash(&quot;flash&quot;, &quot;You have successfully created an account. The last step is to confirm your email so we know you are legit =].&quot;);
                          return res.redirect('/register');
                      });
                  }
              }) 
          })
      } catch {
          return conn.rollback(function() {
              conn.destroy();
              req.flash(&quot;flash&quot;, 'A server error has occurred.');
              res.redirect('/register');
          });
      }
  });  
  </code></pre>