# Auto Log-off

**URL:** <https://forums.knack.com/t/auto-log-off/9770>\
**Category:** Feature Requests\
**Tags:** users-logins, security\
**Created:** [February 9, 2015, 4:39pm UTC](https://forums.knack.com/t/auto-log-off/9770 "2015-02-09T16:39:00Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Srosene67506](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@Srosene67506](https://forums.knack.com/u/Srosene67506)\
**Post date:** [February 9, 2015, 4:39pm UTC](https://forums.knack.com/t/auto-log-off/9770/1 "2015-02-09T16:39:00Z")

</div>

Add an 'auto log-off' of the system after 10 minutes. This promotes security measures and ensures no one can stay logged in consistently (or walk away leaving protected information available).

---

<div class="post-metadata">

**Author:** ![ajsmith78238](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@ajsmith78238](https://forums.knack.com/u/ajsmith78238)\
**Post date:** [June 4, 2019, 1:51pm UTC](https://forums.knack.com/t/auto-log-off/9770/2 "2019-06-04T13:51:53Z")

</div>

I used the code that Sam Carney posted and it works great. However, is there a way to only run the script when a user is logged in? Otherwise the script keeps trying to run after logout.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![LauraTheis](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@LauraTheis](https://forums.knack.com/u/LauraTheis)\
**Post date:** [January 16, 2018, 2:11pm UTC](https://forums.knack.com/t/auto-log-off/9770/3 "2018-01-16T14:11:08Z")

</div>

The original request on this thread was for an inactivity logout feature (auto log-off) and&nbsp;we're excited to announce that this feature is now available for&nbsp;Pro, Corporate and Plus plans!

You can read about how to set up Inactivity Logout under your app's User Logins in our "[Live App Security Settings: Inactivity Logout](https://forums.knack.com/hc/en-us/articles/115003582451-Live-App-Security-Settings#inactivity-logout)" article.

&nbsp;

_For the other feature requests contained within this thread, please be sure to add your vote to other forum posts that cover your request or if one doesn't exist, be sure to add one._

---

<div class="post-metadata">

**Author:** ![RobertSmit95449](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@RobertSmit95449](https://forums.knack.com/u/RobertSmit95449)\
**Post date:** [July 21, 2016, 3:00pm UTC](https://forums.knack.com/t/auto-log-off/9770/4 "2016-07-21T15:00:02Z")

</div>

Hi everyone,

I'm soliciting again on this feature request forum, as I received positive feedback from Knack users in regards to the Tracking User Logins feature thread. We've developed a script that does the following:

1. The user is automatically logged out of the system after a period of inactivity (X minutes) determined by a variable in the script you can update yourself.

2. The user is automatically logged out of the system the moment they close the webpage or browser (this includes refreshing the webpage).

We can install the patch on your system for $267.87 USD. If you are interested, please give me an email at [RobertSmith@datacove.ca](mailto:RobertSmith@datacove.ca) and we can get that in place for you.

Thanks again,

Robert

---

<div class="post-metadata">

**Author:** ![SheilaSata78024](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@SheilaSata78024](https://forums.knack.com/u/SheilaSata78024)\
**Post date:** [May 6, 2016, 7:17pm UTC](https://forums.knack.com/t/auto-log-off/9770/5 "2016-05-06T19:17:30Z")

</div>

This works great. &nbsp;Thank you. &nbsp;However, this only works if the page is left open and idle. &nbsp;Is there a way to be able to automatically log the user out when they close the page?

---

<div class="post-metadata">

**Author:** ![Campguy2317311](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/campguy2317311/32/625_2.png) [@Campguy2317311](https://forums.knack.com/u/Campguy2317311)\
**Post date:** [December 15, 2015, 9:41pm UTC](https://forums.knack.com/t/auto-log-off/9770/6 "2015-12-15T21:41:40Z")

</div>

That helped a lot. Thank you!!!

---

<div class="post-metadata">

**Author:** ![Soluntech](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/soluntech/32/780_2.png) [@Soluntech](https://forums.knack.com/u/Soluntech)\
**Post date:** [December 15, 2015, 9:19pm UTC](https://forums.knack.com/t/auto-log-off/9770/7 "2015-12-15T21:19:51Z")

</div>

Hi&nbsp;Campguy23

You want to add that script withi a scene handler. Something like this:

$(document).on('knack-page-render.scene\_123', function () {

&nbsp; window.onload = timedRefresh(30000);

});

function timedRefresh(timeoutPeriod) {

&nbsp;setTimeout("location.reload(true);",timeoutPeriod);

}

Please chane the "scene\_123" for the correct value.

Hope these helps.

---

<div class="post-metadata">

**Author:** ![Campguy2317311](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/campguy2317311/32/625_2.png) [@Campguy2317311](https://forums.knack.com/u/Campguy2317311)\
**Post date:** [December 15, 2015, 8:44pm UTC](https://forums.knack.com/t/auto-log-off/9770/8 "2015-12-15T20:44:33Z")

</div>

I've managed to get ALL my pages refreshing with the following script:

function timedRefresh(timeoutPeriod) {

&nbsp;setTimeout("location.reload(true);",timeoutPeriod);

}

window.onload = timedRefresh(30000);

Now if someone could just help me figure out how to get this script to work on only ONE of my pages, I'll be set!

---

<div class="post-metadata">

**Author:** ![Campguy2317311](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/campguy2317311/32/625_2.png) [@Campguy2317311](https://forums.knack.com/u/Campguy2317311)\
**Post date:** [December 15, 2015, 7:50pm UTC](https://forums.knack.com/t/auto-log-off/9770/9 "2015-12-15T19:50:53Z")

</div>

Sam, how might the script look if we wanted the page to refresh ie every time an inline edit or record change was made on a table within the page?&nbsp;

Or even a script with just a straight auto-refresh of the page at a specified time interval would be very helpful.&nbsp;

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Tarikyouse27964](https://avatars.discourse-cdn.com/v4/letter/t/977dab/32.png) [@Tarikyouse27964](https://forums.knack.com/u/Tarikyouse27964)\
**Post date:** [October 21, 2015, 6:23pm UTC](https://forums.knack.com/t/auto-log-off/9770/10 "2015-10-21T18:23:41Z")

</div>

I am interested in this function. Where would I place this code?

---

<div class="post-metadata">

**Author:** ![Soluntech](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/soluntech/32/780_2.png) [@Soluntech](https://forums.knack.com/u/Soluntech)\
**Post date:** [September 9, 2015, 4:32am UTC](https://forums.knack.com/t/auto-log-off/9770/11 "2015-09-09T04:32:35Z")

</div>

Hi Sam, thanks for your reply. I manage to get it working. Wrapped the code around the $(document).ready(function() {}) Jquery handler and it worked!&nbsp;

Cheers for asking!

Alejandro

---

<div class="post-metadata">

**Author:** ![SamCarney81930](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@SamCarney81930](https://forums.knack.com/u/SamCarney81930)\
**Post date:** [September 9, 2015, 12:54am UTC](https://forums.knack.com/t/auto-log-off/9770/12 "2015-09-09T00:54:19Z")

</div>

Alejandro,

Do you mind posting the exact code you are using? I’ve had mine working successfully for about a month now.

---

<div class="post-metadata">

**Author:** ![Soluntech](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/soluntech/32/780_2.png) [@Soluntech](https://forums.knack.com/u/Soluntech)\
**Post date:** [September 8, 2015, 5:04pm UTC](https://forums.knack.com/t/auto-log-off/9770/13 "2015-09-08T17:04:51Z")

</div>

Hello friends, wonder if this auto log-off ever worked? I tested Sam's javascript, nonetheless the setInterval method doesn't seem to be looping ... Wonder if it's something related to Knack's platform?&nbsp;

Will appreciate your thoughts

Best

Alejandro

---

<div class="post-metadata">

**Author:** ![SamCarney81930](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@SamCarney81930](https://forums.knack.com/u/SamCarney81930)\
**Post date:** [July 30, 2015, 3:37am UTC](https://forums.knack.com/t/auto-log-off/9770/14 "2015-07-30T03:37:16Z")

</div>

Try this.

&nbsp;

```
var idleTime = 0;
$(document).ready(function () {
//Increment the idle time counter every minute.
var idleInterval = setInterval(timerIncrement, 60000); // 1 minute

```
//Zero the idle timer on mouse movement.
$(this).mousemove(function (e) {
    idleTime = 0;
});
$(this).keypress(function (e) {
    idleTime = 0;
});

```

});

function timerIncrement() {  
idleTime = idleTime + 1;  
if (idleTime \> 19) { // 20 minutes  
$(".kn-log-out").trigger(“click”);  
}  
}
```

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![JeffZearfo11770](https://avatars.discourse-cdn.com/v4/letter/j/aca169/32.png) [@JeffZearfo11770](https://forums.knack.com/u/JeffZearfo11770)\
**Post date:** [February 9, 2015, 9:15pm UTC](https://forums.knack.com/t/auto-log-off/9770/15 "2015-02-09T21:15:44Z")

</div>

(I don't know javascript well, so your mileage may vary.)

---

<div class="post-metadata">

**Author:** ![JeffZearfo11770](https://avatars.discourse-cdn.com/v4/letter/j/aca169/32.png) [@JeffZearfo11770](https://forums.knack.com/u/JeffZearfo11770)\
**Post date:** [February 9, 2015, 9:15pm UTC](https://forums.knack.com/t/auto-log-off/9770/16 "2015-02-09T21:15:06Z")

</div>

I assume this is possible with a little javascript. Perhaps something like this?

```
window.setTimeout(function(){ window.location.href = "https://builder.knackhq.com/cccatering/catering-db#logout"; 

```
</span><span>}, </span><span>60000</span><span>);</span></pre>
```
```

---

<div class="post-metadata">

**Author:** ![Jessie](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/jessie/32/5_2.png) [@Jessie](https://forums.knack.com/u/Jessie)\
**Post date:** [July 2, 2021, 6:54pm UTC](https://forums.knack.com/t/auto-log-off/9770/17 "2021-07-02T18:54:29Z")

</div>

Closed on July 2, 2021, 6:54pm UTC


