Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logged out of the MIQ website after X hours (stops the script) #91

Open
BananaHammock743 opened this issue Jul 28, 2021 · 4 comments
Open

Comments

@BananaHammock743
Copy link

Describe your problem
Has anyone else started to be logged out of the MIQ website after X hours (which obviously causes the script to stop running)? Yesterday I came back to my computer and I'd been logged out, with no error message, just the login page showing again.

This morning the same thing happened at approx 5:50pm (NZ time)

I have checked with my partner (the only other person with our login details) and they had not logged in recently which would have caused the expected "single session" logout.

To clarify: I'm not saying this is a miq-nz-booking-tools issue, jut something to be aware of if the MIQ website has started logging users out after X hours. This could also be a local computer issue only I'm experiencing.

Steps yo reproduce

  1. Using v0.10.2.exe enter detail (dates, etc) into the app and login to the MIQ website
  2. Website is refreshed as expected
  3. Wait X hours
  4. Come back to computer and see that I've been logged out of the MIQ website

Steps you have taken so far
Turned off screensaver completely
Turned off screen from turning off after X min
Turned off sleep after X min
Network adapter settings > Power Management > "Allow the computer to turn off this device to save power" > disabled

Your system (please complete the following information):
Win10, using miq-nz-booking-assistance-Windows-v0.10.2.exe with Chromium browser

@jvolker jvolker changed the title Question: Anyone else getting logged out of the MIQ website after X hours (stops the script)? logged out of the MIQ website after X hours (stops the script) Jul 28, 2021
@BananaHammock743
Copy link
Author

BananaHammock743 commented Jul 29, 2021

Saw this prompt when I got up in the middle of the night to check.

Could be related to the website update braking the script, and then because of inactivity in the page it showed up.
log out prompt

@alexDrinkwater
Copy link
Collaborator

I'm seeing this too after about 1.5 hours. This might be a new security feature.

@nikhil-bhandari
Copy link

nikhil-bhandari commented Jul 29, 2021

Hi,

Thanks for maintaining this script. This is what I used to detect and avoid auto logouts.

What this does is detect the modal and then clicks on "OK".

const selectors = {
  logout: {
    dialog: {
      window: "#session-expire-time-dialog.dialog-open",
      button: ".btn.btn-secondary"
    },
  }
};

// returns boolean
async function hasLogoutDialog(page) {
  return page.evaluate((selectors) => {
    const {window} = selectors;

    const logoutDialog = document.querySelector(window)

    console.log(!!logoutDialog);

    return !!logoutDialog;
  }, selectors.logout.dialog);
}

Main Function that handles logout dialog

async function handleAutoLogout(page) {
  const hasLogout = await hasLogoutDialog(page);

  if (!hasLogout) {
    return;
  }

  console.log("Found logout dialog.");

  const redirectUrl = await page.url();
  console.log("Handling logout.");

  await page.evaluate((selectors) => {
    setInterval(handleAutoLogout, 1000);

    function handleAutoLogout() {
      const {window, button} = selectors;

      const logoutDialog = document.querySelector(window);

      if (logoutDialog) {
        document.querySelector(`${window} ${button}`).click();
      }
    }
  }, selectors.logout.dialog);

  await page.waitForNavigation({waitUntil: ["networkidle0", "domcontentloaded"], timeout: 0})

  console.log("Redirecting to following url: ", redirectUrl);

  await page.goto(redirectUrl);
}

And here is the code to trigger auto logout for testing purposes. (Yes! there is a span that is clicked programatically to show the Auto Logout modal on miq's website :| )

document.getElementById("session-expire-time").click()

Usage

await handleAutoLogout();

@alexDrinkwater
Copy link
Collaborator

@nikhil-bhandari Thanks! Are you willing to create a pull request with those changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants