title: Can't set headers after they are sent...no issue until I added in authentication?
body: <p>I'm having some issues trying to send an axios requests with custom headers from my app so I can use them for authentication on my server.</p>
  
  <p>I have a react native app that uses firebase authentication and a  node/express backend server.</p>
  
  <p>When a user signs in, I will grab their firebase idtoken and store it.</p>
  
  <p>I will then send that idtoken as a header whenever I  make an axios request to the server.</p>
  
  <pre><code> const { currentUser } = firebase.auth();
  
    const url = ${serverUrl}/api/users/${user.uid`;
  
    const idtoken = await currentUser.getToken(true);
  
      var config = {
        headers: { idtoken },
      };
  
  const response = await axios(url, config);
  </code></pre>
  
  <p>In the server code, there will be an express middleware that checks whether the idtoken sent in the request header is valid or not. If it is, it will call next() and proceed to execute the logic. If not, then it'll fail and send a 401 status.</p>
  
  <p>This is in my <code>app.js</code>:</p>
  
  <pre><code>const app = express();
  
  
    app.use(bodyParser.json());
  
    app.use(firebaseAuthentication);
    router(app);
  </code></pre>
  
  <p>This is the <code>firebaseAuthentication</code> middleware:</p>
  
  <pre><code>const firebaseAuthentication = async (req, res, next) =&gt; {
    console.log(req);
    try {
      const { idtoken } = req.headers;
  
      await admin.auth().verifyIdToken(idtoken);
      next();
    } catch (e) {
      res.status(401).send({ error: 'Unauthorized request. Must be signed in via firebase' });
    }
  };
  </code></pre>
  
  <p>This is the router:</p>
  
  <pre><code>module.exports = app =&gt; {
  
      app.get('/api/users/:firebaseUID', UserController.getUser);
  }
  </code></pre>
  
  <p>The issue is that everything seems to go through until it tries to send the good data back to the user...but I get a <code>404</code> and a <code>Error:  Can't set headers after they are sent</code></p>
  
  <p>This is the specific request that is failing:</p>
  
  <pre><code>  async getUser(req, res, next) {
      const firebaseUID = req.params.firebaseUID;
      try {
        const user = await User.findOne({ firebaseUID });
  
        res.send(user);
      } catch (e) {
        next(e);
      }
    },
  </code></pre>
  
  <p>What is happening here and how can I fix it? Thanks!</p>