<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Laravel\Jetstream\Http\Middleware\AuthenticateSession;

class ConditionalAuthenticateSession
{
    protected $authenticateSession;

    public function __construct(AuthenticateSession $authenticateSession)
    {
        $this->authenticateSession = $authenticateSession;
    }

    public function handle(Request $request, Closure $next)
    {
        // Skip AuthenticateSession middleware in Docker environment
        // as it causes session validation issues with session migration
        if (env('IS_DOCKER', false)) {
            return $next($request);
        }

        return $this->authenticateSession->handle($request, $next);
    }
}
