<?php

namespace App\Http\Middleware;

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

class AccessTokenMiddleware
{
    public function handle(Request $request, Closure $next)
    {
        if (!Session::has('access_token') && !$request->is('login')) {
            return redirect()->route('login')->withErrors(['login_error' => 'Você precisa fazer login primeiro.']);
        }

        return $next($request);
    }
}
