[Vuejs]-Laravel sanctum works in localhost, but returns 401 unauthenticated in live server

0👍

I think you should define home url in the blade page you use vue app like this.

<script>
      window.home = "<?php echo your-host-url ?>";
</script>

To make sure the API route is correct you add:

axios.get(window.home + '/api/user').then(response => {
    this.userInfo = response.data
})

-1👍

The solution is adding this to .htaccess of root folder (not only inside the public folder)

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

Leave a comment