0

I try to access my Laraval API from my Vue SPA but everytime I do a request I get a 401 Unauthorized. I have tried the answers from multiple SO questions but nothing works.

  • I added the EnsureFrontendRequestsAreStateful to the API middleware.
  • I set the Valet domain that I use for SANCTUM_STATEFUL_DOMAINS=goya.app.
  • I set the session envs:
    SESSION_DRIVER=cookie
    SESSION_LIFETIME=120
    SESSION_DOMAIN=.goya.app
    
  • In Vue I have axios.defaults.withCredentials enabled.
  • In the request headers I see that the XSRF token is sent.

What else can I try to fix this?

Bart Bergmans
  • 4,061
  • 3
  • 28
  • 56
  • 1
    Are you making _csrf-cookie_ request before you make any API Calls ? [SPA Authentication](https://laravel.com/docs/7.x/sanctum#spa-authenticating) – Raja Sep 10 '20 at 02:16
  • Ah, I did not. Is it possible to ignore this since it's a public API? Or is there a way to do the request before every call if the csrf-cookie isn't set yet? – Bart Bergmans Sep 11 '20 at 15:56

0 Answers0