Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Alewa's avatar
Level 2

Laravel sanctrum api login error with react js

When I try to login to my react js react frontend website using laravel 9 sanctrum api login functionality, I am getting this two error Access to XMLHttpRequest at 'http://jaano.test/sanctum/csrf-cookie' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values '*, http://localhost:3000', but only one is allowed. and xhr.js:258 GET http://jaano.test/sanctum/csrf-cookie net::ERR_FAILED This is my api.php file

<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTION');
header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Auth-Token');

//http://jaano.test/api/users
// Route::get('users',  [\App\Http\Controllers\API\ApiV1UserController::class, 'getUsers']);

Route::namespace('App\Http\Controllers\API')->group(function(){
    //Register user api route
    Route::post('register','ApiV1UserController@register');

    //Login user api route
    Route::post('login','ApiV1UserController@login');
}```
ApiUserController.php file
0 likes
0 replies

Please or to participate in this conversation.