/**
  * Starts up the session, looks for remember me if there was no session
  * Also updates the session if the user is flagged for it.
  *
  * @throws Exception
  */
 public function startSession()
 {
     // If the session has a cookie, start it
     if (Session::hasSessionCookie() && Session::start() && Session::hasRole(UserRole::USER)) {
         ChatIntegrationService::instance()->renewChatSessionExpiration(Session::getSessionId());
     }
     // Check the Remember me cookie if the session is invalid
     if (!Session::hasRole(UserRole::USER)) {
         $user = $this->getRememberMe();
         if (!empty($user)) {
             Session::start();
             Session::updateCredentials($this->getUserCredentials($user, 'rememberme'));
             $this->setRememberMe($user);
             // flagUserForUpdate updates the credentials AGAIN, but since its low impact
             // Instead of doing the logic in two places
             $this->flagUserForUpdate($user['userId']);
         }
     }
     // Update the user if they have been flagged for an update
     if (Session::hasRole(UserRole::USER)) {
         $userId = Session::getCredentials()->getUserId();
         if (!empty($userId) && $this->isUserFlaggedForUpdate($userId)) {
             $user = UserService::instance()->getUserById($userId);
             if (!empty($user)) {
                 $this->clearUserUpdateFlag($userId);
                 Session::updateCredentials($this->getUserCredentials($user, 'session'));
                 // the refreshChatSession differs from this call, because only here we have access to the session id.
                 ChatIntegrationService::instance()->setChatSession(Session::getCredentials(), Session::getSessionId());
             }
         }
     }
 }