jwt-auth
jwt-auth copied to clipboard
Auth driver [jwt] for guard [api] is not defined
Auth driver [jwt] for guard [api] is not defined.
Your environment
Q | A |
---|---|
Bug? | no |
New Feature? | no |
Framework | Lumen |
Framework version | 6.3.5 |
Package version | 1.0.0-rc.5 |
PHP version | 7.2 |
My Application was working without any error, i am using lumen 6.3.5 and jwt 1.0.0-rc5 when i deploy the application again and make composer install, i get this error
PHP Fatal error: Uncaught InvalidArgumentException: Auth driver [jwt] for guard [api] is not defined. in /var/www/html/proj/vendor/illuminate/auth/AuthManager.php:97
Stack trace:
#0 /var/www/html/proj/vendor/illuminate/auth/AuthManager.php(68): Illuminate\Auth\AuthManager->resolve('api')
#1 /var/www/html/proj/vendor/illuminate/auth/AuthManager.php(307): Illuminate\Auth\AuthManager->guard()
#2 /var/www/html/proj/app/Exceptions/Handler.php(44): Illuminate\Auth\AuthManager->__call('user', Array)
#3 /var/www/html/proj/vendor/sentry/sentry/src/State/Hub.php(98): App\Exceptions\Handler->App\Exceptions\{closure}(Object(Sentry\State\Scope))
#4 /var/www/html/proj/vendor/sentry/sentry/src/functions.php(78): Sentry\State\Hub->configureScope(Object(Closure))
#5 /var/www/html/proj/app/Exceptions/Handler.php(48): Sentry\configureScope(Object(Closure))
#6 /var/www/html/proj/vendor/laravel/lumen-framework/src/Concerns/RegistersExceptionHandlers.php(122): App\Exce in /var/www/html/proj/vendor/illuminate/auth/AuthManager.php on line 97
now i cannot make any artisan command like (php artisan cache:clear) every time i try to do anything i get the same error. by the way the code was working 100% and i was using jwt.
this is my bootstrap/app.php:
$app->routeMiddleware([
'auth' => App\Http\Middleware\Authenticate::class,
'throttle' => App\Http\Middleware\ThrottleRequests::class,
]);
$app->withFacades(true, [
Tymon\JWTAuth\Facades\JWTAuth::class => 'JWTAuth',
Tymon\JWTAuth\Facades\JWTFactory::class => 'JWTFactory',
]);
$app->register(App\Providers\AuthServiceProvider::class);
$app->register(Tymon\JWTAuth\Providers\LumenServiceProvider::class);
and this is the auth file:
'defaults' => [
'guard' => env('AUTH_GUARD', 'api'),
'passwords' => 'users',
],
'guards' => [
'api' => [
'driver' => 'jwt',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
],
Same issue here.
Laravel 8.0 PHP 7.4 tymon/jwt-auth: ^1.0
In laravel 8.0, same issue if i set default to "api", but if i use Auth::guard('api'), the error will be "Method Illuminate\Auth\SessionGuard::factory does not exist."
Same here!!!!!!Any answer???
Same problem here while installing Laravel Masterpass plugin.
same here
no solutions yet ?
For me this happened after I upgraded to Laravel 7. According to the upgrade guide App\Exceptions\Handler
now uses Throwable
instead of Exception
. If you have traits used in this handler, update those too.
This worked for me https://github.com/tymondesigns/jwt-auth/issues/1886#issuecomment-538448309 on Laravel 6.0
Leave the default guard as it is and do this:
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'jwt',
'provider' => 'users',
'hash' => false,
],
],
Then just call:
auth('api')->attempt([....etc
Leave the default guard as it is and do this:
'defaults' => [ 'guard' => 'web', 'passwords' => 'users', ], 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'jwt', 'provider' => 'users', 'hash' => false, ], ],
Then just call:
auth('api')->attempt([....etc
THANKS FRIEND
I solved the problem by adding this line to the providers in app.php
Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
and here is guards I have:
`
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api_customer' => [
'driver' => 'jwt',
'provider' => 'api_customer',
],`
after following @RichieMcMullen 's solution now my error becomes Method Illuminate\Auth\SessionGuard::factory does not exist.
anyone found the solution?
after following @RichieMcMullen 's solution now my error becomes Method Illuminate\Auth\SessionGuard::factory does not exist.
anyone found the solution?
If you follow @RichieMcMullen's solution and then also add the ServiceProvicer as @AbdulrazakZakieh suggestes it will work fine.