1<?php
2
3namespace App\Http\Middleware;
4
5use Closure;
6use JWTAuth;
7use Exception;
8use Tymon\JWTAuth\Http\Middleware\BaseMiddleware;
9
10class JwtMiddleware extends BaseMiddleware
11{
12
13 /**
14 * Handle an incoming request.
15 *
16 * @param \Illuminate\Http\Request $request
17 * @param \Closure $next
18 * @return mixed
19 */
20 public function handle($request, Closure $next)
21 {
22 try {
23 $user = JWTAuth::parseToken()->authenticate();
24 } catch (Exception $e) {
25 if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenInvalidException){
26 return response()->json(['status' => 'Token is Invalid']);
27 }else if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenExpiredException){
28 return response()->json(['status' => 'Token is Expired']);
29 }else{
30 return response()->json(['status' => 'Authorization Token not found']);
31 }
32 }
33 return $next($request);
34 }
35}