bebeboutik-api/app/Web/Middlewares/Authenticate.php
Christophe LATOUR 56c4d72708 Throw exception instead of returning raw response
- We throw the exception to let the Handler.php handling the error
2017-08-04 16:13:54 +02:00

46 lines
1013 B
PHP

<?php
namespace App\Web\Middlewares;
use Closure;
use Illuminate\Contracts\Auth\Factory as Auth;
use \Illuminate\Http\Request;
use Symfony\Component\HttpKernel\Exception\HttpException;
class Authenticate
{
/**
* The authentication guard factory instance.
*
* @var \Illuminate\Contracts\Auth\Factory
*/
protected $auth;
/**
* Create a new middleware instance.
*
* @param \Illuminate\Contracts\Auth\Factory $auth
* @return void
*/
public function __construct(Auth $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle(Request $request, Closure $next, $guard = null)
{
if ($this->auth->guard($guard)->guest()) {
throw new HttpException(401, 'Unhautorized');
}
return $next($request);
}
}