gdarko / laravel-vue-starter

Latest Laravel 11 and Vue 3 boilerplate using Tailwind 3, Sanctum, Fortify, Pinia, the new Vue3 Composition API
92 stars 44 forks source link

CSRF token mismatch. #11

Open menphurk236 opened 1 year ago

menphurk236 commented 1 year ago

image

run command : php artisan serve

my .env config APP_URL=http://127.0.0.1:8000 SANCTUM_STATEFUL_DOMAINS=127.0.0.1:8000 SESSION_DOMAIN=localhost

gdarko commented 1 year ago

Hey @menphurk236

I have no idea what could be wrong because i don't use artisan serve.

I recommend to run this project with Laravel Homestead or Laravel Valet.

Best Regards, Darko

krishnahimself commented 1 year ago

Hello @menphurk236,

I've added the following environment variables with these values:

APP_URL=http://localhost:8000/ SANCTUM_STATEFUL_DOMAINS=localhost:8000 SESSION_DOMAIN=localhost SPA_URL="${APP_URL}" This adjustment resolved the issue.

Best Regards, Krishna

fecoderchinh commented 1 year ago

I have fixed this issue by change the browser url to http://localhost:8000 By default, if you press ctrl + click on the url on your terminal, then browser will open http://127.0.0.1:8000 This will cause the problem.

c4sti3l commented 18 hours ago

I had the same problem, my solution was to add the crsf token to "resources/app/plugins/axios.js"

axios.defaults.headers.common['X-CSRF-TOKEN'] = window.AppConfig.csrf;

The token is correctly set in "resources/views/index.blade.php" but not used. After adding this line, the error disappears.