public function loginFrontEndUser($userId)
    {
        if ((int)$userId === 0) {
            throw new \InvalidArgumentException('The user ID must be > 0.', 1334439475);
        }
        if (!$this->hasFakeFrontEnd()) {
            throw new Exception('Please create a front end before calling loginFrontEndUser.', 1334439483);
        }

        if ($this->isLoggedIn()) {
            $this->logoutFrontEndUser();
        }

        $this->suppressFrontEndCookies();

        // With current TYPO3 versions we have to ensure an user id
        $tempUser = [
            $GLOBALS['TSFE']->fe_user->userid_column => $userId,
        ];
        $GLOBALS['TSFE']->fe_user->createUserSession($tempUser);
        $GLOBALS['TSFE']->fe_user->user = $GLOBALS['TSFE']->fe_user->getRawUserByUid($userId);
        $GLOBALS['TSFE']->fe_user->fetchGroupData();
        $GLOBALS['TSFE']->loginUser = 1;
    }