You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB
PHP

<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class AuthAdmin extends Middleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next, ...$guards)
{
if (auth()->check() && auth()->user()->type === 'Admin') {
return $next($request);
}
if ($request->ajax()) {
$errorCode = 403;
$result = [
"message" => '권한이 없습니다.',
"success" => false,
"data" => [],
"errors" => []
];
// logger(json_decode(json_encode($result), true));
$headers = [];
return response()->json($result, $errorCode, $headers, JSON_UNESCAPED_UNICODE);
} else {
$data = [
'exception' => new AccessDeniedHttpException()
];
return response()->view('errors', $data);
}
}
}