<?php
namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;

class memberAuth
{
    /**
     * Handle an incoming request.
     */
    public function handle(Request $request, Closure $next): Response
    {

        // 使用 'member' 守衛進行身份驗證
        if (!Auth::guard('member')->check()) {
            // 未登入，記錄日誌並重導向

            \Log::warning('Unauthorized access attempt.', ['url' => $request->url()]);
            return redirect()->route('login');
        }

        // 驗證成功，繼續處理請求
        return $next($request);
    }
}
