Lae/app/Http/Middleware/Authenticate.php

47 lines
967 B
PHP
Raw Normal View History

2022-08-12 07:56:56 +00:00
<?php
namespace App\Http\Middleware;
2022-09-08 16:12:02 +00:00
use Closure;
use App\Helpers\ApiResponse;
use Illuminate\Contracts\Auth\Factory as Auth;
2022-08-12 07:56:56 +00:00
2022-09-08 16:12:02 +00:00
class Authenticate
2022-08-12 07:56:56 +00:00
{
2022-09-08 16:12:02 +00:00
use ApiResponse;
2022-08-12 07:56:56 +00:00
/**
2022-09-08 16:12:02 +00:00
* 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.
2022-08-12 07:56:56 +00:00
*
* @param \Illuminate\Http\Request $request
2022-09-08 16:12:02 +00:00
* @param \Closure $next
* @param string|null $guard
* @return mixed
2022-08-12 07:56:56 +00:00
*/
2022-09-08 16:12:02 +00:00
public function handle($request, Closure $next, $guard = null)
2022-08-12 07:56:56 +00:00
{
2022-09-08 16:12:02 +00:00
if ($this->auth->guard($guard)->guest()) {
2022-09-08 16:37:04 +00:00
return $this->unauthorized('Unauthorized.');
2022-08-12 07:56:56 +00:00
}
2022-09-08 16:12:02 +00:00
return $next($request);
2022-08-12 07:56:56 +00:00
}
}