I'm on the newer side of Laravel and am trying to setup an API. I have been following the tutorial at http://www.toptal.com/web/cookie-free-authentication-with-json-web-tokens-an-example-in-laravel-and-angularjs
I've been following along and think I understand what is going on but am stumped with the part on adding the validation to the route.
I have a Route::group setup with the following code included before any methods.
try {
JWTAuth::parseToken()->toUser();
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], HttpResponse::HTTP_UNAUTHORIZED);
}
When the user is not authenticated, the statement throws an exception as intended but the return statement causes a 404 and not the expected response.
If I comment out the return line, the rendering continues and shows the secured content.
I cannot for the life of me figure out whey the return response would pop a 404 and not the expected json.
Any guidance would greatly be appreciated.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community