First, go to your Laravel app and find the file cors.php

app→config→cors.php and set it to like below

'supports_credentials' => true,

And most important if you are working on Localhost then go to the .env file and  paste the below code.



Now go to your React app and then open the file where you called axios.

axios.get('/sanctum/csrf-cookie').then(response => {`api/register`, data).then(res => {



axios.get('/sanctum/csrf-cookie').then(response => }) will generate csrf token.

Then go to your main file App.js and paste below code


axios.defaults.withCredentials = true;

axios.defaults.baseURL="";  you can leave this line.

Thanks for reading if any query comment me.

Leave a Comment
Advik Comment on: 18-11-2023 11:11:57

This blog really help me. Thanks