sampang's avatar

CSRF token mismatch

Hello everyone , I'm trying to make an API in laravel and frontend in nuxtjs. I made basic authentication system in laravel with sanctum and it is working with postman. But when i make a request from my frontend(nuxt app) it shows csrf token mismatch error. What should i do ?

0 likes
4 replies
Nakov's avatar

You are hitting a route that is in your web.php file most probably and not in your api.php. That middleware is applied to the web group here, so make sure you are making calls properly.

Run php artisan route:list and you'll see which middleware is applied to the route you are trying to hit.

1 like
sampang's avatar

@Nakov

i have my api routes in api.php

submit() { axios.post('http://localhost:8000/api/user/register',this.form) /* eslint-disable */ .then((res) => console.log(res.data)) .catch((e) => (this.errors = e.response.data.errors)) }

i have a form that makes request as showed in above submit method.

i have my routes as following in api.php

Route::post('/user/register',[UserController::class,'register']);

Please or to participate in this conversation.