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?
Hi Erik,
Thanks for your question!
This has been discussed on the Community before - you can find the full question and discussion here. There is currently no in-built functionality within Create to achieve this, but a possible approach is to use a 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:
// 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();
2 Likes