5

I followed the official JWT-Auth installation https://github.com/tymondesigns/jwt-auth/wiki/Installation.

I now have a middleware in my controller:

$this->middleware('jwt-auth', ['only' => ['postChange', 'postChoose']]);

I have also add Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class to providers array in config/app.php

However when I make a request to the API I get this error message:

ReflectionException in Container.php line 737:
Class jwt-auth does not exist

Any help at all will be appreciated.

3 Answers 3

13

I have the same problem to use the middlewares you will have to register them in app/Http/Kernel.php under the $routeMiddleware property:

protected $routeMiddleware = [
    ...
    'jwt.auth' => 'Tymon\JWTAuth\Middleware\GetUserFromToken',
    'jwt.refresh' => 'Tymon\JWTAuth\Middleware\RefreshToken',
];
Sign up to request clarification or add additional context in comments.

5 Comments

I have registered it ..are you using jwt.auth or jwt-auth as the middleware
@digitlimit I am using jwt.auth as middleware.
Thanks. Seems the official documentation is not very informative.
Do you run PHPUnit tests? I am trying to make a request by using token in a test getting errors
Remember to place those single quotes ('). They are very important.
3

I have been facing a similar issue. You have to add exactly

protected $routeMiddleware = [
    .......
    'jwt.auth' => \Tymon\JWTAuth\Middleware\GetUserFromToken::class,
    'jwt.refresh' => \Tymon\JWTAuth\Middleware\RefreshToken::class,
];

Remember the "\" at the begining.

Laravel 5.2

1 Comment

Valid in laravel 8 as well
2

I had the same problem and turned out that "\" is required on the begin of the path (per analogy to the other middleware entries) :

'jwt.auth' => \Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class

and this resolved my problem (Laravel 5.1.4)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.