Skip to main content

Hi All,

I am trying to implement session timeout functionality for my experience cloud public page. I tried using session timeout for guest user profile from the Salesforce setup but this method is not working. The page consists of custom LWCs. If there is any way to implement this with javascript or Apex, please let me know your answers.

3 respostas
  1. 13 de dez. de 2024, 13:02

    Hi @Shreya Bhandare,

    Salesforce session timeout doesn’t apply to Guest Users because they aren’t considered logged in. To handle this, implement a client-side inactivity timer using JavaScript in your custom LWC.

     

    How It Works:

    Track Inactivity: Use JavaScript events like mousemove, keydown, or touchstart.

    Set Timeout: Trigger a timer for 15 minutes (900,000 ms).

    Action on Timeout: Refresh the page or redirect the user.

     

    Example JS Code:

     

    let timeout;

    function resetTimer() {

    clearTimeout(timeout);

    timeout = setTimeout(() => {

    window.location.reload(); // Or redirect to logout

    }, 900000); // 15 minutes

    }

    // Attach listeners

    window.onload = resetTimer;

    document.onmousemove = resetTimer;

    document.onkeydown = resetTimer;

0/9000