/** * Handle the command. * * @param $command * * @throws \Tectonic\Shift\Modules\Authentication\Exceptions\TokenNotFoundException * @return mixed */ public function handle($command) { // 1. Get token record $token = $this->tokenRepository->getByToken($command->token); // 2. If token record does NOT exist, throw exception if (!$token) { throw new TokenNotFoundException(); } // 3. Authenticate user $data = $this->getTokenData($token); $authUser = $this->auth->loginUsingId($data->userId); // 4. Delete token record $this->tokenRepository->delete($token); // 5. Return authenticated user return $authUser; }
public function switchToUserId($userId, $remember = false) { $this->auth->loginUsingId($userId, $remember); }