Support the ongoing development of Laravel.io →
posted 10 years ago
Requests

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.

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

kisonay kisonay Joined 13 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.