In the wiki under the Authentication section there is info for Middleware and Filters.
Now these are references i.e. as 'jwt.auth' => 'Tymon\JWTAuth\Middleware\GetUserFromToken'
When this is used I have no way (other than making changes in the package) of modifying how the response is assembled. It's this i.e. in the BaseMiddleware@response:
return $response ?: $this->response->json(['error' => $error], $status);
Would you change this and publish the middleware and reference to the App\Http\Middleware folder so that we have a way to modify how the response is assembled according to our structure?
Is there a better way to do this?
It seems to me that the only way to customize the response is by defining event listeners.
Event::listen('tymon.jwt.invalid', function () {
return Response::make(['your_custom_error' => 'token invalid'], 400);
});
Thanks Zerazeru, I'll try this out and close the issue for now.
Great, works.
The documentation didn't mention where to add this. After looking here it's clear: https://laravel.com/docs/5.4/events
Add these lines in app/Providers/EventServiceProvider.php
Event::listen('tymon.jwt.invalid', function () {
return \Response::make(['your_custom_error' => 'token invalid'], 400);
});
Thanks again Zerazeru.
Most helpful comment
Great, works.
The documentation didn't mention where to add this. After looking here it's clear: https://laravel.com/docs/5.4/events
Add these lines in app/Providers/EventServiceProvider.php
Thanks again Zerazeru.