Jwt-auth: auth driver [jwt] for guard [api] not defined

Created on 3 Oct 2019  路  2Comments  路  Source: tymondesigns/jwt-auth

Subject of the issue

When running a post request inside a unit test,

$response = $this->post(route('teams.store'), ['name' => $teamName]);

it would throw an error saying

auth driver [jwt] for guard [api] not defined

For some reason, it appears that the service provider was not loaded that extends to include the JWT functionality. After I manually include

Tymon\JWTAuth\Providers\LaravelServiceProvider::class,

into config/app.php the unit test passes.

What is also important to mention is that when I run those same requests through Postman, I receive correct responses including the access_token.

Am I missing anything within my test suite?

Thanks for this awesome package!

Your environment

| Q | A
| ----------------- | ---
| Bug? | yes (?)
| New Feature? | no
| Framework | Laravel
| Framework version | 6.1.0
| Package version | 1.0.5
| PHP version | 7.3.6

Most helpful comment

Thank you @jeremynikolic ! That was the solution to the problem

All 2 comments

Encountered the same issue, after a bit of research it seems to be related to test config files being cached, files are located in bootstrap/cache:

  • config.phpunit.php
  • events.phpunit.php
  • packages.phpunit.php
  • services.phpunit.php

Have a look here for further info :
https://github.com/laravel/framework/issues/13374

Personnaly, manually deleting those files and running tests again fixed the problem. Fixes are proposed in the thread

Thank you @jeremynikolic ! That was the solution to the problem

Was this page helpful?
0 / 5 - 0 ratings