Login a user for api tokens middleware

parent 74bc58bc
......@@ -4,6 +4,7 @@ namespace Modules\User\Http\Middleware;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Modules\User\Contracts\Authentication;
use Modules\User\Repositories\UserTokenRepository;
class AuthorisedApiToken
......@@ -12,10 +13,15 @@ class AuthorisedApiToken
* @var UserTokenRepository
*/
private $userToken;
/**
* @var Authentication
*/
private $auth;
public function __construct(UserTokenRepository $userToken)
public function __construct(UserTokenRepository $userToken, Authentication $auth)
{
$this->userToken = $userToken;
$this->auth = $auth;
}
public function handle(Request $request, \Closure $next)
......@@ -35,6 +41,8 @@ class AuthorisedApiToken
{
$found = $this->userToken->findByAttributes(['access_token' => $this->parseToken($token)]);
$this->auth->logUserIn($found->user);
if ($found === null) {
return false;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment