I am sending an API request to get user detail after login I have a project in which I am running APIs only, I placed this project in sub-directory which has name api. so front-end is running on the root which is built in react JS.
also, I have removed the API prefix from RouteServiceProvider because I don't want to call domain.com/api/api
Route:
Route::group(['namespace' => 'Auth'], function(){
...
Route::post('login','LoginController@login'); // Running successfully
Route::middleware('auth:api')->get('/user', 'LoginController@user'); // Returning 401 unauthenticated
});
RouteServiceProvider
protected function mapApiRoutes()
{
Route::middleware('api')
->as('api.')
->namespace($this->namespace."\\API")
->group(base_path('routes/api.php'));
}
Tried solutions
1) I have placed Passport::withoutCookieSerialization();
inside boot
method in AppServiceProvider
2) I have placed the Passport::$ignoreCsrfToken = true;
inside boot
method in AuthServiceProvider
Thank you so much for your kind help.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire