<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class EnsureLauncherRequest
{
    public function handle(Request $request, Closure $next): Response
    {
        abort_unless(
            filled(config('auth.launcher_auth_key'))
                && hash_equals(config('auth.launcher_auth_key'), (string) $request->header('Auth')),
            Response::HTTP_FORBIDDEN,
            'Недостаточно прав для доступа к админке.',
        );

        return $next($request);
    }
}
