Answer the question
In order to leave comments, you need to log in
Why is auth:api blocking cors in laravel?
Axios refers to laravel
const sessionid = localStorage.getItem('sessionid');
const headers = {
Authorization: 'Bearer ' + sessionid,
'Content-type': 'application/json'
}
responseApi = axios({
method: 'get',
url: 'http://127.0.0.1:8000/api/v1/companies',
headers: headers,
});
Route::group(['middleware' => [ 'cors', 'auth:api']], function() {
Route::resource('v1/companies', 'CompanyAPIController');
});
class Cors
{
public function handle($request, Closure $next)
{
$response = $next($request);
return $response
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE')
->header('Access-Control-Request-Headers', 'X-Authentication, Authorization')
->header('Access-Control-Allow-Headers', 'Content-Type, X-Auth-Token, Origin');
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question