kamal gharejeloo
kamal gharejeloo

Reputation: 349

Laravel 5.8 Auth guard [api] is not defined

When I use auth api guard for my controller I am facing with the following exception

Auth guard [api] is not defined

When I remove Authorization in request header, my controller work is true but when I add Authorization and accept to request header, I get this error.

My route:

Route::group(['prefix' => 'category','middleware' => 'auth:api'], function () {
  Route::post('add', 'Api\CategoryController@addCategory');
  Route::post('edit', 'Api\CategoryController@editCategory');
  Route::get('get/{id}', 'Api\CategoryController@getCategory');
  Route::get('get', 'Api\CategoryController@getCategory');
  Route::get('delete', 'Api\CategoryController@deleteCategory');
});

auth.php file:

 'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'passport',
        'provider' => 'users',
        'hash' => false,
    ],
],

and i added Passport::routes() to AuthServiceProvider.php and i migrated passport migration and i installed passport for create passport client access

i think every thing is ok but get error

Upvotes: 1

Views: 2967

Answers (1)

AWS PS
AWS PS

Reputation: 4708

You need to clear config cache to take effect. for Unauthenticated it means token is not valid or is not passed correctly

https://laravel.com/docs/5.7/passport#passing-the-access-token

Upvotes: 1

Related Questions