# Background refresh

**URL:** <https://community.appfarm.io/t/background-refresh/1012>\
**Category:** Ask the community\
**Created:** [January 30, 2024, 10:22am UTC](https://community.appfarm.io/t/background-refresh/1012 "2024-01-30T10:22:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erik](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/erik/32/78_2.png) [@Erik](https://community.appfarm.io/u/Erik)\
**Post date:** [January 30, 2024, 10:22am UTC](https://community.appfarm.io/t/background-refresh/1012/1 "2024-01-30T10:22:35Z")

</div>

Hi, is there a way to check if a user has been inactive for a certain period of time. And if so, refresh the application or trigger an action?

---

<div class="post-metadata">

**Author:** ![rhys](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/rhys/32/1379_2.png) [@rhys](https://community.appfarm.io/u/rhys)\
**Post date:** [January 30, 2024, 3:16pm UTC](https://community.appfarm.io/t/background-refresh/1012/2 "2024-01-30T15:16:22Z")

</div>

Hi Erik,

Thanks for your question!

This has been discussed on the Community before - you can find the full question and discussion [here](https://community.appfarm.io/t/handling-inactive-users/926). There is currently no in-built functionality within Create to achieve this, but a possible approach is to use a [coded component](https://docs.appfarm.io/library/ui-components/coded-component) to track user activity, such as typing or moving the mouse. A logout action can then be triggered from within the coded component.

I have copied and pasted the example function below, for convenience and further reference if others have a similar use case:

```auto
// Set the inactivity timeout value in milliseconds (e.g., 15 minutes)
const inactivityTimeout = 15 * 60 * 1000; // 1 minute

let logoutTimer;

function resetLogoutTimer() {
  // Clear existing timer
  clearTimeout(logoutTimer);

  // Set a new timer
  logoutTimer = setTimeout(logoutUser, inactivityTimeout);
}

function logoutUser() {
  // Perform logout actions 
  appfarm.actions.logout()
    .then(() => console.log('User logged out due to inactivity!'))
    .catch(console.error)
}

// Event listeners to track user activity
function handleUserActivity() {
  resetLogoutTimer();
}

document.addEventListener("mousemove", handleUserActivity);
document.addEventListener("keydown", handleUserActivity);

// Initial setup
resetLogoutTimer();

```
