Skip to content

Commit

Permalink
fix: Failed Authentication Response
Browse files Browse the repository at this point in the history
  • Loading branch information
jiannei committed Apr 16, 2021
1 parent d2a7d62 commit e088b0c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Support/Traits/ExceptionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,15 @@ protected function invalidJson($request, ValidationException $exception)

/**
* Custom Failed Authentication Response for Laravel.
* @param Request $request
* @param AuthenticationException $exception
* @return JsonResponse
*
* @param Request $request
* @param AuthenticationException $exception
* @return \Illuminate\Http\RedirectResponse | JsonResponse
*/
protected function unauthenticated($request, AuthenticationException $exception)
{
return app(Response::class)->errorUnauthorized($exception->getMessage());
return $request->expectsJson()
? app(Response::class)->errorUnauthorized($exception->getMessage())
: redirect()->guest($exception->redirectTo() ?? route('login'));
}
}

0 comments on commit e088b0c

Please sign in to comment.