Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ImWaller's avatar

Laravel Vue Spa with Fortify and Sanctum return unauthorized user after succeful login.

Hello Laravelers,

Today I just want to try the fortify as a SPA with Vue and I have the 401 unauthorized error. All I need a user to login and logout for now. I follow all the steps on the docs and I check the internet for solutions but I was unlikely. My vue is inside the laravel on the same domain. In fortify configs i turn off the views. I change the App url to the project url laravel.test. Then follow the docs and some examples to build the app.

Problem: Login successfully but when called the /api/user then return 401

Questions:

  1. I need to setup the SANCTUM_STATEFUL_DOMAINS on the sanctum configs?
  2. Need to wrap the vue app instance with attemptUser or doesnt need?
attemptUser().finally(() => {
  const app = createApp(App)
  app.use(router)
  app.mount('#app')
}))
0 likes
1 reply
ImWaller's avatar
ImWaller
OP
Best Answer
Level 1

I didnt had the EnsureFrontendRequestsAreStateful on the kernel.

1 like

Please or to participate in this conversation.