artur
October 3, 2022, 2:22pm
1
The script below will log out users after a period of inactivity.
<script>
function idleTimer() {
var t;
window.onload = resetTimer;
window.onmousemove = resetTimer; // catches mouse movements
window.onmousedown = resetTimer; // catches mouse movements
window.onclick = resetTimer; // catches mouse clicks
window.onscroll = resetTimer; // catches scrolling
window.onkeypress = resetTimer; //catches keyboard actions
function logout() {
deleteCookie('jwtToken');
window.location.href = '/';
}
function resetTimer() {
clearTimeout(t);
t = setTimeout(logout, 1800000); // time is in milliseconds (1000 is 1 second)
}
function deleteCookie(name) {
document.cookie = name + "=;path=/; expires=Thu, 01 Jan 1970 00:00:00 UTC" + ";" + 'SameSite=None; Secure';
}
}
idleTimer();
</script>
based on Inactivity timeout javascript · GitHub
11 Likes
Hi Artur ! Thanks for your tips, this makes sense if we have the ability to disconnect users even if they leave the page, after a certain period of time (by the API for example). In the same principle of securing a banking site. Any idea about that?
artur
February 9, 2023, 6:10pm
4
We have received some requests to make this code work on dekstop but not on mobile
The code below will do the trick.
instead of calling
idleTimer();
one would need to do this
const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
if(!isMobile) {
idleTimer();
}
@artur , where does this code go? I’ve tried putting it in the header section of the custom code area but not getting any results.
1 Like
I would also love to know where should the code go!
artur
May 24, 2023, 4:25pm
7
@nocodeking and @UtroBG app settings custom code header area.
2 Likes
bbelo
July 3, 2023, 3:00pm
8
Is there a way to log out a user conditionally (and right away after login), if their account status (kept in airtable) has a particular value?
Thank you
Boris