<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nathan Loyer</title>
    <description>The latest articles on DEV Community by Nathan Loyer (@namlet).</description>
    <link>https://dev.to/namlet</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F944048%2Fc6f2dda7-1175-4314-9021-51c335153aab.png</url>
      <title>DEV Community: Nathan Loyer</title>
      <link>https://dev.to/namlet</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/namlet"/>
    <language>en</language>
    <item>
      <title>Can't get Axios requests to PHP API</title>
      <dc:creator>Nathan Loyer</dc:creator>
      <pubDate>Fri, 14 Oct 2022 16:19:53 +0000</pubDate>
      <link>https://dev.to/namlet/cant-get-axios-requests-to-php-api-5c0n</link>
      <guid>https://dev.to/namlet/cant-get-axios-requests-to-php-api-5c0n</guid>
      <description>&lt;p&gt;Not sure where to start here. I have inherited a Laravel 7.4/ Vue 2.x application. Everyone who knew how to start it up (in theory: successfully) is long gone. I've got everything up and listening without errors until you try to do anything. It's supposed to be setup with the Laravel app listening for &lt;code&gt;/api&lt;/code&gt; calls. And in the Vue app an &lt;code&gt;Api&lt;/code&gt; object is created by Axios.&lt;/p&gt;

&lt;p&gt;The problem I am struggling with is that all requests to this &lt;code&gt;Api&lt;/code&gt; return with a 401 Unauthorized. But the PHP server isn't even getting a request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import axios from "axios";

let baseURL = "";

switch (process.env.NODE_ENV) {
    case "development":
        baseURL = window.location.protocol + "//" + window.location.hostname + "/api";
        break;

    default:
        baseURL = window.location.protocol + "//" + window.location.hostname + "/api";
}

axios.defaults.withCredentials = true;

const Api = axios.create({
    baseURL,
    withCredentials: true
});

export default Api;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'm using all the sanctum csrf stuff to manage the token and I'm not getting CSRF errors anymore after fixing the config in &lt;code&gt;.env&lt;/code&gt;. Now all I get are 401s, and they are coming from Nginx. Any ideas? I've been stuck on this for days and don't know where to go next.&lt;/p&gt;

</description>
      <category>vue</category>
      <category>laravel</category>
      <category>nginx</category>
      <category>axios</category>
    </item>
  </channel>
</rss>
