<?php

namespace App\Http\Middleware;

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

class CheckClientSession
{
    /**
     * Handle an incoming request.
     *
     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next
     */
    public function handle(Request $request, Closure $next): Response
    {
        if(!$request->session()->has('current_user')){
            // dd('in the Middleware');
            return redirect(url('client-login'))->withErrors("Enter Credentials to gain access");
        }
        // dd('before next in the Middleware');
        return $next($request);
    }
}
