This might help: https://laracasts.com/discuss/channels/laravel/react-csrf
Dec 30, 2024
6
Level 1
CSRF Token Issue
Hi there, I am new in react, and I try to create a user management system. i make controller for CRUD operations. i use react as frontend with breeze. on localhost, every task working perfectly like, creating edit and delete. but when i push code on server (heroku), its show error (419) while creating, edit, or delete. user.tsx:
const handleDelete = () => {
router.delete(route("users.destroy", selectedUser?.id), {
preserveScroll: true,
preserveState: true,
onSuccess: () => {
toast.success("User has been deleted successfully");
setSelectedUser(undefined);
},
});
};
How I can add csrf token there, it's work on localhost perfectly but show error 419 on server. I am check bootstrap/app.php but there is no middleware for csrf bootstrap/app.php:
<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->web(append: [
\App\Http\Middleware\HandleInertiaRequests::class,
\Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets::class,
]);
//
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
How I can fix this issue?
Please or to participate in this conversation.