<?php

namespace App\Game\Services;

use App\Http\Controllers\Game\LoginController;
use Closure;

class CheckGameLogin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        $user = LoginController::checkLogin($request);
        if ($user) {
            $request->globalUser = $user;
            $request->setUserResolver(function () use ($user) {
                return $user;
            });
        }

        return $next($request);
    }
}
