Where have you declared your api routes ? In the api.php file or in the web.php file ?
Furthermore your API routes should be protected by the sanctum middleware like this.
Route::middleware('auth:sanctum')->group(function () {
...
});
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi everyone,
My simple web application consists of a Laravel API as backend and a React App as frontend. The application is accessible through https://example.com and makes requests to the API via https://api.example.com. The API should only be called by the frontend and should not be accessed directly.
For example my frontend calls https://api.example.com/items to fetch all items. However, it should NOT be possible for users to directly access the endpoint in their browser via https://api.example.com/items. So, requests to the API endpoints should only be possible through the frontend.
I have already installed and configured Sanctum and updated the CORS configuration in config/cors.php. Unfortunately, I don't no which further configuration steps are needed since I don't need the user authentication.
So, is there a way to secure my endpoints without implementing authentication?
Please or to participate in this conversation.