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

vincent15000's avatar

Laravel / Sanctum / VueJS / Axios / ERROR 401

Hello,

The authentication works fine, but when I try to retrieve some data, I get a 401 error (unauthenticated).

I have checked the request headers and the tokens are sent.

I don't see what I could check to solve this issue.

Thanks for your help ;).

Vincent

0 likes
4 replies
vincent15000's avatar

@SilenceBringer Here is the login code.

async login(user) {
  await api.get('/sanctum/csrf-cookie')
  await api.post('/login', { email: user.email, password: user.password })
  let response = await api.get('/api/user')
  return response.data
},

The first two lines work fine, but the API call to retrieve the user doesn't work and generates a 401 error.

boyjarv's avatar

I'm having a very similar issue, can anyone help? Please

1 like
vincent15000's avatar
vincent15000
OP
Best Answer
Level 63

@boyjarv I just solved the problem.

For me the front and the back are on the same domain, but on different subdomains.

In this case, the SESSION_DOMAIN has to be defined with a dot (as if there were a wildcard).

SESSION_DOMAIN=.mydomain.com

Please or to participate in this conversation.