-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Returning custom response from events #6
Comments
After testing this myself, I can see that you are indeed correct. The event is fired but anything returned from the event is lost. Which is an oversight on my part :( The reason is because the event is not being returned from the filter, so the response never 'goes anywhere'. I think I have a fix in mind for this, which I will try to implement at some point today. For now, to get the custom responses you want, you could create your own filter in Route::filter('custom-jwt', function ($route, $request)
{
if ( ! $token = JWTAuth::getToken($request) )
{
return Response::json(['error' => 'token_not_provided'], 400);
}
try
{
$user = JWTAuth::toUser($token);
}
catch(Tymon\JWTAuth\Exceptions\TokenExpiredException $e)
{
return Response::json(['error' => 'token_expired'], 401);
}
catch(Tymon\JWTAuth\Exceptions\JWTException $e)
{
return Response::json(['error' => 'token_invalid'], 400);
}
if (! $user)
{
return Response::json(['error' => 'user_not_found'], 404);
}
}); and replace those Responses with your own. As soon as I have a fix for this, I will post it here. Thanks! |
Issue is now resolved and tagged as a new release ( |
…espace changed namespace to PHPOpenSourceSaver
First, thank you for a great library! Made my life a lot simpler.
I'm attempting to return my own response when a user sends an invalid token in order to have my API consistent. I've created an
events.php
file under app/ and hooked into the appropriate event:However this doesn't seem to change anything, I'm still getting this response returned:
I know the event is firing because if I
die("test")
inside it, I seetest
.How would you recommend I return my own response?
The text was updated successfully, but these errors were encountered: