Skip to content

Instantly share code, notes, and snippets.

@casgin
Created November 29, 2018 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save casgin/27abb781312c0b1ef105cfa3850edb3d to your computer and use it in GitHub Desktop.
Save casgin/27abb781312c0b1ef105cfa3850edb3d to your computer and use it in GitHub Desktop.
// === Recupero del Token
$token = JWTAuth::getToken();
// --- logica del middleware
try {
// --- inoltra il token e verifica che sia corretto
$user = JWTAuth::toUser($token);
} catch (JWTException $e) {
if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenExpiredException) {
return response()->json(['token_expired'], $e->getStatusCode());
} else if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenInvalidException) {
return response()->json(['token_invalid'], $e->getStatusCode());
} else {
return response()->json(['error' => 'Token obbligatorio']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment