res.redirect creating another request on the same route
<p>This is my first time here, so I hope I post this correctly.</p>
<p>I am working with Loopback here, and I am having a problem when I try to redirect to another route.
Basically I have two middlewares. The first, checks with Firebase if the user if authenticated and allowed to visit /dashboard. If no, I call the next() middleware and this one redirects back to /login again.</p>
<p>Dashboard.js:</p>
<pre><code>'use strict';
    const firebase = require(&quot;firebase&quot;);
    exports.dashboard = (req, res, next) =&gt; {
      firebase.auth().onAuthStateChanged((user) =&gt; {
          if (user) {
            console.log(&quot;Before render: &quot;+res.headersSent); // false
            res.render(&quot;dashboard&quot;, {photoUrl: user.photoURL, displayName: user.displayName, email: user.email });
            console.log(&quot;after render: &quot;+res.headersSent);
          } else {
            // console.log(&quot;on else&quot;  );
            next()
          }
      });
    
    };
    
    exports.notLogged = (req, res) =&gt; {
      console.log(&quot;no one logged in&quot;);
      res.redirect('/login');
    };
</code></pre>
<p>Route on server.js:</p>
<pre><code> app.get('/dashboard', dashboard.dashboard, dashboard.notLogged);
</code></pre>
<p>The middleware on login.js:</p>
<pre><code>exports.login = (req, res) =&gt; res.render(&quot;login&quot;)
</code></pre>
<p>And its route:</p>
<pre><code>app.get('/login', login.login);
</code></pre>
<p>For example, if I try to access &quot;/dashboard&quot; and I am not logged, the &quot;console.log(&quot;no one logged in&quot;); &quot; will be twice on the console, or any other log on the flow. It looks like another request was made, but I can't understand why or how. If I remove the redirect and simply end the response or render a page, the problem does not occur.</p>
<p>Thank you! :)</p>
<p><strong>UPDATE</strong></p>
<p>I am back here and still with no solution. This is driving me crazy.</p>
<p><a href="https://i.stack.imgur.com/mWt6R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mWt6R.png" alt="Double GET happening after res.redirect :(" /></a></p>