5
votes

I am using laravel 5.4 and using jwt auth jwt version is jwt-auth "tymon/jwt-auth": "0.5.*"

In auth.php i have

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

        'api' => [
            'driver' => 'jwt',
            'provider' => 'users',
        ],
    ],

In Api.php i have

 Route::post('/login','HomeController@authenticate');


Route::group(['prefix' => 'v2','middleware' => 'auth:api',], function () {

    // Authentication Routes...
   Route::get('/logout','HomeController@logout');
Route::get('/home','HomeController@home');

});

When i post email and password from postman it will return token .

when i try to acccess

http://localhost/demo/public/api/v2/home

and header i passed Authorization bearer token

I am getting following error in postman

Whoops, looks like something went wrong. (1/1) InvalidArgumentException Auth guard driver [api] is not defined. in AuthManager.php (line 99) at AuthManager->resolve('api') in AuthManager.php (line 70) at AuthManager->guard('api') in Authenticate.php (line 61) at Authenticate->authenticate(array('api'))

can any help me how to fix it

Also i checked follwing issue since its old one Sep 27, 2016 https://github.com/tymondesigns/jwt-auth/issues/860

3

3 Answers

0
votes

Make sure in your kernel.php file you've declared it in

 protected $routeMiddleware = 
0
votes

try to set token:

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

        'api' => [
            'driver' => 'token', // here !
            'provider' => 'users',
        ],
    ],
0
votes

Not necessarily an answer, but this is the article I have used a couple times to install and setup JWT tokens and I have had no issues.

https://medium.com/employbl/build-authentication-into-your-laravel-api-with-json-web-tokens-jwt-cd223ace8d1a

Hopefully this helps, good luck!