<?php

declare(strict_types=1);

namespace App\Http\Middleware;

use Closure;
use Illuminate\Foundation\Http\Middleware\ValidateCsrfToken;
use Illuminate\Http\Request;

class ConditionalValidateCsrfToken extends ValidateCsrfToken
{
    public function handle($request, Closure $next): mixed
    {
        if ($request instanceof Request && $request->attributes->get('skinbase.session_skipped') === true) {
            return $next($request);
        }

        return parent::handle($request, $next);
    }
}