title: ECONNREFUSED 127.0.0.1:80 when trying to sign in using next-auth
body: <p>I use <a href="https://next-auth.js.org/" rel="noreferrer">next-auth.js</a> library to create authentication system for Next.js my application.
  Everything works fine on my local computer, but after deploying website to <a href="https://vercel.com/" rel="noreferrer">Vercel</a>, my sign in function doesn't work.</p>
  <p>The sign in page <code>(/pages/signin)</code> loads fine, i submit credentials and i get an error like this:
  <code>https://projectname-git-branch.username.now.sh/api/auth/error?error=Error%3A%20connect%20ECONNREFUSED%20127.0.0.1%3A80</code>.</p>
  <p>I found many articles that error is about to wrong <code>baseURL</code> configured for <code>axios</code>, but i have many <code>axios</code> requests everywhere in code (for example i get data from firebase after app loads) and it works without any problem.</p>
  <p>I console logged environment variable where i set <code>baseURL</code> property for <code>axios</code> and it's fine.</p>
  <pre class="lang-js prettyprint-override"><code>// _app.js
  import axios from 'axios';
  axios.defaults.baseURL = process.env.FIREBASE_APIURL;
  console.log('axios-baseurl', axios.defaults.baseURL) // it prints right url
  </code></pre>
  <p>More informations about this problem i wrote there: <a href="https://github.com/nextauthjs/next-auth/issues/846" rel="noreferrer">#846</a></p>
  <p>I really don't know what to do. I don't get any information about where this error happens, which file and line number, what request in my code.</p>
  <p>Below i put my whole <code>[...nextauth.js]</code> file and sign in form. Maybe there is something what i should to configure better there.</p>
  <pre class="lang-js prettyprint-override"><code>// [...nextauth.js]
  import NextAuth from 'next-auth'
  import Providers from 'next-auth/providers'
  
  import axios from 'axios';
  axios.defaults.baseURL = process.env.FIREBASE_APIURL;
  console.log('axios-baseurl', axios.defaults.baseURL)
  
  const sha1 = require('crypto-js/sha1');
  const md5 = require('crypto-js/md5');
  
  export default (req, res) =&gt; 
      NextAuth(req, res, {
          providers: [
              Providers.Credentials({
                  name: 'Credentials',
                  credentials: {
                      phone: { label: &quot;Numer telefonu&quot;, type: &quot;text&quot; },
                      password: { label: &quot;Haslo&quot;, type: &quot;password&quot; }
                  },
                  authorize: async (loginData) =&gt; {
                      const { csrfToken, phone, password } = loginData;
                      
                      //  checking if there is account with these credentials
                      let res = await login({
                          phone, 
                          password: sha1(md5(password)).toString()
                      })
  
                      //  200 = OK
                      if(res.status == 200){
                          //  check if account was activated
                          if(res.data.info.activated == &quot;true&quot;){
                              //  collect account data
                              const user = {
                                  phone,
                                  ...res.data.info
                              }
                              return Promise.resolve(user);
                          }
                          else{
                              //  account is not activated by sms code
                              return Promise.reject(new Error(&quot;AccountNotActivated&quot;));
                          }
                      }
                      else {
                          //  wrong credentials
                          return Promise.reject(new Error(&quot;WrongCredentials&quot;));
                      }
                  }
              })
          ],
          callbacks: {
              jwt: async (token, user, account, profile, isNewUser) =&gt; {
                  user &amp;&amp; (token.user = user);
                  return Promise.resolve(token)
              },
              session: async (session, user, sessionToken) =&gt; {
                  session.user = user.user;
                  return Promise.resolve(session)
              }
          },
          
          pages: {
              signIn: '/signin'
          },
          
          site: process.env.NEXTAUTH_URL || &quot;localhost:3000&quot;,
          debug: true
      })
  
  
  //  function which sends login request to rest api and returns result
  //  https://stackoverflow.com/q/64244115
  const login = async data =&gt; await axios.post('/checkCredentials', data);
  
  </code></pre>
  <pre class="lang-html prettyprint-override"><code>&lt;!-- /pages/signin.js --&gt;
  &lt;form action=&quot;/api/auth/callback/credentials&quot; method=&quot;post&quot;&gt;
      &lt;input name='csrfToken' type='hidden' defaultValue={csrfToken} /&gt;
      &lt;label&gt;
          Numer telefonu: &lt;br /&gt;
          &lt;input name='phone' type='text' required autoComplete='off' /&gt;
      &lt;/label&gt;
      &lt;br /&gt;
      &lt;label&gt;
          Hasło: &lt;br /&gt;
          &lt;input name='password' type='password' required autoComplete='off' /&gt;
      &lt;/label&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;input type=&quot;submit&quot; value=&quot;Zaloguj&quot; /&gt;
  &lt;/form&gt;
  </code></pre>