* * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ namespace App\Http\Middleware; use App\Repositories\Enums\ResponseCodeEnum; use Closure; use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Contracts\Auth\Factory as Auth; use Illuminate\Http\Request; class Authenticate { /** * The authentication guard factory instance. * * @var Auth */ protected $auth; /** * Create a new middleware instance. * * @param Auth $auth */ public function __construct(Auth $auth) { $this->auth = $auth; } /** * Handle an incoming request. * * @param Request $request * @param Closure $next * @param string|null $guard * * @return mixed * * @throws AuthorizationException */ public function handle($request, Closure $next, $guard = null) { if ($this->auth->guard($guard)->guest()) { abort(ResponseCodeEnum::HTTP_UNAUTHORIZED); } return $next($request); } }