Hi, could you please review your sanctum configuration and ensure your fetch request is passing the correct headers and cookies?
useFetch("/api", {
headers: {
accept: "application/json",
},
credentials: "include"
})
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, I'm trying to consume a Laravel API from a NUXT application using useFectch but I'm getting a "CSRF token mismatch" error.
Starting from the beginning...
I wrote my Laravel API that is intended to check user login and reply with a sanctum token. this is my route inside api.php
Route::controller(RegisterController::class)->group(function(){ Route::post('login', 'login'); }); the controller method accept as input parameters email and password
if I call myapi this way from Postman, setting the 2 parameters in the body this way { "email": "[email protected]", "password": "qdIekoUx" }
it works perfectly sending me the Sanctum token that I will use in the next calls.
Instead if I call the same API from my javascript app (NUXT 3) thisway const reqData = { "email": "[email protected]", "password": "qdIekoUx" } const { data, error } = await useFetch('https://myapi.it/api/login', { method: 'POST', body: reqData }) console.log(data)
it replies with "CSRF token mismatch"; I don't understand why! If I understood well Laravel API routes do not perform a CSRF validation...
Anyone can help me?
Please or to participate in this conversation.