Good day! I’m picking up with Rest API on Laravel, and honestly speaking my head has already come from all this hurts. With the principles it turned out, I get a token, send a request to the site with a token and get user data in response. I didn’t do much for this: http://jwt-auth.readthedocs.io/en/docs/quick-start/
But here's the problem, if you specify the wrong token in the header (or the token which time has expired), redirects to the login request page. And here I wanted to use foul language, because before that I also tried to do laravel / passport and there it was the same thing. The bottom line is that the JSON response should be returned with an error, instead I redirect to the site, I can’t do it anyway, I just reread it in the article net. I tried to create my intermediaries and check in them, I tried to add something like this:
public function handle($request, Closure $next) { try { if (! $user = JWTAuth::parseToken()->authenticate()) { return response()->json(['user_not_found'], 404); } } catch (TokenExpiredException $e) { return response()->json(['token_expired'], $e->getStatusCode()); } catch (TokenInvalidException $e) { return response()->json(['token_invalid'], $e->getStatusCode()); } catch (JWTException $e) { return response()->json(['token_absent'], $e->getStatusCode()); } return $next($request); } and not only here, but a similar code was written in the intermediary ... Well, I can't get rid of it. Plus documentation - like a cat crying. Tell me what you can do. Maybe you have some links to good articles about this or examples of how it is done (both on jwt-auth and on laravel / passport, the latter is more like, there is more or less documentation, plus I see where tokens are stored and Other data is in the database, but I don’t understand how jwt works). I ask you not to throw stones, I am new to this business, I have been studying Laravel for about 2 months, and with the API less than a week ... If you need some other info, I’m ready to provide it.
Exceptions > Handler.phpchange unauthenticated or addAccept: application/json- Orange_shadow to the request header