title: undefined jwt token react/express
body: <p>I am implementing a JWT authentication on a login/registration system. When there is a successful login/registration I am setting a user token in localStorage.</p>
  
  <p>Problem is when I check my localStorage the user key is present but the value is undefined. I think the issue might be in my axios post or in my express file but I can't quite figure it out.</p>
  
  <pre><code>// my action creator
  export function login(user, history) {
  return async (dispatch) =&gt; {
    axios.post('/api/login', { user })
    .then(res =&gt; {
        dispatch({ type: AUTHENTICATED });
        localStorage.setItem('user', res.data.token);
        history.push('/');
    })
    .catch((error) =&gt; {
        dispatch({
            type: AUTHENTICATION_ERROR,
            payload: 'Invalid email or password'
        });
    });
   };
  }
  </code></pre>
  
  <p>The data is reaching my api correctly. The item is being set but the value res.data.token is undefined.. Below is my express file</p>
  
  <pre><code>// login.js (/api/login)
  router.post('/', function(req, res) {
  var email = req.body.user.email;
  var password = req.body.user.password;
  // TODO: create db file and import connection
  var connection = mysql.createConnection({
      host: "localhost",
      user: "root",
      password: "",
      database: "dbname",
      port: 3307
  });
  
  connection.connect(function(err) {
      if(err) {
          console.log(err);
      } else {
          connection.query("SELECT ID, Password FROM Users WHERE Email = ?", [email], function(err, result) {
              if(err) {
                  console.log('Could not find account');
                  res.send(err);
              } else {
  
                  var id = result[0].ID;
  
                  bcrypt.compare(password, result[0].Password, function(err, result) {
                      if(result) {
                          console.log(id);
                          res.json({ id });
                      } else {
                          console.log('Incorrect password');
                      }
                  });
              }
          });
        }
      });
  });
  </code></pre>
  
  <p>Since the res.data.token in my action creator is returning undefined does that mean the response in my express file ( res.json([id]) ) is just returning defined?</p>