Laravel(Homestead) Sanctum not working with Seperate Vue app

  javascript, laravel, laravel-sanctum, vue.js

I have run

 php artisan serve

and my laravel app is resolved on localhost:8000 successfully

Laravel Sanctum configuration

 SESSION_DRIVER=cookie
 SESSION_DOMAIN=localhost
 SANCTUM_STATEFUL_DOMAINS=localhost:8080

My vue app is resolved on localhost:8080

 async loginUser() {
    try {
    await this.$axios.get('/csrf-cookie');
    await this.$axios.post('/login', this.payload);
    this.$router.push("/verify/account");
  } catch(error) {
    let errors = error.response.data.errors;
    for (let field of Object.keys(errors)) {
    this.$toast.error(errors[field][0], 'error');
  }
}

},

This works and the user is logged in but GET, POST request returns a 401 unauthenticated all the time.
I’ve checked the request headers and the cookie and X-XSRF-TOKEN are sent but i get a 401 everytime.

Source: Laravel

Leave a Reply