Inactivity timeout

This already exists now though. You can check it out in the settings under SSO
image

This will log you out regardless of activity or inactivity.

+1 for this feature please it would be extremely useful!

Thanks for all the +1s! I don't have an update yet, but I will post here if that changes

1 Like

+1

Heya y'all!

I'm not seeing any updates on a Retool native feature for this, yet, but I was able to build out this functionality using custom components.

You can use this code snippet here to get your custom component started:

const IDLE_TIMEOUT_MINUTES = 5; // Customize timeout here
const IDLE_TIMEOUT_MS = IDLE_TIMEOUT_MINUTES * 60 * 1000;

export const idleTimeout: FC = () => {
  const [signedOut, setSignedOut] = Retool.useStateBoolean({
    name: "signedOut", 
    initialValue: false
  })
  useEffect(() => {
    let idleTimer: ReturnType<typeof setTimeout>;

    const resetIdleTimer = () => {
      clearTimeout(idleTimer);
      idleTimer = setTimeout(() => {
        handleSignOut();
      }, IDLE_TIMEOUT_MS);
    };

    const handleSignOut = () => {
      // Trigger the Retool query to log out
      setSignedOut(true)

      // Optional: redirect after query triggers
      window.location.href = "/login"; // Update path as needed
    };

    // List of user events to listen to
    const activityEvents = ["mousemover", "keydown", "scroll", "click"];

    activityEvents.forEach((event) =>
      window.addEventListener(event, resetIdleTimer)
    );

    // Start timer on mount
    resetIdleTimer();

    // Cleanup
    return () => {
      activityEvents.forEach((event) =>
        window.removeEventListener(event, resetIdleTimer)
      );
      clearTimeout(idleTimer);
    };
  }, [signedOut]);

  return (
    <div>
      <p>You will be signed out after {IDLE_TIMEOUT_MINUTES} minute(s) of inactivity.</p>
    </div>
  );
}

You'll then want to connect the variable that is exported from the component to the parent app in a dummy SQL resource that runs each time the variable changes. Once successfully run and with the variable stating that the user should be logged out, you can trigger a success event to navigate to your instances logout url like so:


Hope this helps!

1 Like