Skip to content

Commit

Permalink
fixing issue where responses returned from events not working - closes
Browse files Browse the repository at this point in the history
  • Loading branch information
tymondesigns committed Oct 24, 2014
1 parent 28b2410 commit 1d200d6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Tymon/JWTAuth/JWTAuthFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public function filter($route, $request)
{
if ( ! $token = $this->auth->getToken($request) )
{
$this->events->fire('tymon.jwt.absent');
return Response::json(['error' => 'token_not_provided'], 400);
$response = $this->events->fire('tymon.jwt.absent', [], true);
return $response ?: Response::json(['error' => 'token_not_provided'], 400);
}

try
Expand All @@ -45,19 +45,19 @@ public function filter($route, $request)
}
catch(TokenExpiredException $e)
{
$this->events->fire('tymon.jwt.expired', $e->getMessage());
return Response::json(['error' => 'token_expired'], 401);
$response = $this->events->fire('tymon.jwt.expired', $e->getMessage(), true);
return $response ?: Response::json(['error' => 'token_expired'], 401);
}
catch(JWTException $e)
{
$this->events->fire('tymon.jwt.invalid', $e->getMessage());
return Response::json(['error' => 'token_invalid'], 401);
$response = $this->events->fire('tymon.jwt.invalid', $e->getMessage(), true);
return $response ?: Response::json(['error' => 'token_invalid'], 401);
}

if (! $user)
{
$this->events->fire('tymon.jwt.user_not_found');
return Response::json(['error' => 'user_not_found'], 404);
$response = $this->events->fire('tymon.jwt.user_not_found', [], true);
return $response ?: Response::json(['error' => 'user_not_found'], 404);
}

$this->events->fire('tymon.jwt.valid', $user);
Expand Down

1 comment on commit 1d200d6

@radiumrasheed
Copy link

@radiumrasheed radiumrasheed commented on 1d200d6 Mar 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

please can you provide a detailed way to implement overriding these response using laravel event listeners

thanks in advance

Please sign in to comment.