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

shaneomac's avatar

shaneomac wrote a reply+100 XP

5mos ago

Laravel Sanctum SPA Auth: 419 Token mismatch error in logout

You should not need this " axiosClient.get('/sanctum/csrf-cookie').then(response => { " What does your app.blade.php look like?

You don't have the CSRF loaded in the head do you?

shaneomac's avatar

shaneomac wrote a reply+100 XP

6mos ago

CSRF - Why is it so painful? Laravel 12 w React/Inertia

@janum Thanks for all that insight!

@jussimannisto It is all become super clear the last few days for me where I have gone wrong. I just wish I knew all this info months ago but never again will I struggle.

Appreciate your responses!

shaneomac's avatar

shaneomac liked a comment+100 XP

6mos ago

CSRF - Why is it so painful? Laravel 12 w React/Inertia

Speaking of LLMs being wrong:

  1. For Inertia, always make the first request visit /sanctum/csrf-cookie A lot of devs forget this step. Once the cookie is set, the CSRF header is handled automatically. No need to manually fetch the token at all.

This is pointless with Inertia. The initial Inertia page response already includes the cookie. You'd only need this step if you had a pure SPA with Laravel as a backend API.