title: 401 Unauthorized error when making axios request
body: <p>I am using axios to make different GET and POST requests to a third-party API that requires a username and password login to access the data. I have tried several approaches to make this work but I keep getting this error in the console.</p>
  <pre><code>data: '&lt;!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML 2.0//EN&quot;&gt;\n' +
        '&lt;html&gt;&lt;head&gt;\n' +
        '&lt;title&gt;401 Unauthorized&lt;/title&gt;\n' +
        '&lt;/head&gt;&lt;body&gt;\n' +
        '&lt;h1&gt;Unauthorized&lt;/h1&gt;\n' +
        '&lt;p&gt;This server could not verify that you\n' +
        'are authorized to access the document\n' +
        'requested.  Either you supplied the wrong\n' +
        'credentials (e.g., bad password), or your\n' +
        &quot;browser doesn't understand how to supply\n&quot; +
        'the credentials required.&lt;/p&gt;\n' +
        '&lt;/body&gt;&lt;/html&gt;\n'
  }
  </code></pre>
  <p>I have been using this approach to send the username and password with node.js</p>
  <pre><code>export const getCameraStream = (req, res) =&gt; {
    let conn = createConnection(config);
    let query = `SELECT * FROM cameras WHERE id = ${req.params.id}`
    conn.connect();
    conn.query(query, async (error, rows, _) =&gt; {
      const camera = rows[0];
      const username = camera.user;
      const password = camera.pass;
        if (error) {
          return res.json({ &quot;status&quot;: &quot;failure&quot;, &quot;error&quot;: error });
        }
  
        const result = await axios({
          method: 'get',
          url: &lt;placeholder for api url&gt;,
          auth: {
            username, password
          }
        })
        console.log(result);
    });
    conn.end();
  }
  
  </code></pre>
  <p>and then use this code on my React front-end</p>
  <pre><code>const getCameraStream = async () =&gt; {
      const username = camera.user
      const password = camera.pass
      try {
        const token = Buffer.from(`${username}:${password}`).toString('base64')
        const res = await publicRequest.get(`camera/getCameraStream/${camera.id}`, {
          headers: {
            'content-type': 'multipart/x-mixed-replace; boundary=--myboundary',
            'Authorization': `Basic ${token}`
          },
          auth: {
            username, password
          }
        })
        console.log(res)
      } catch (error) {
        console.error(error)
      }
    }
  
  </code></pre>
  <p>Using this approach, I am able to pass the username and password to the server and the responseUrl property is correct. However, my app crashes and I keep getting the same unauthorized error in the console. Could this be an issue with the fact that the browser is sending a preflight OPTIONS request or am I overlooking something with my authorization?</p>