Skip to content

Instantly share code, notes, and snippets.

@Azsaturndx
Last active February 25, 2020 06:49
Show Gist options
  • Save Azsaturndx/cf03b6cfc5e3ed4aab55451faedcf8c3 to your computer and use it in GitHub Desktop.
Save Azsaturndx/cf03b6cfc5e3ed4aab55451faedcf8c3 to your computer and use it in GitHub Desktop.
Auto refresh user token - Code onTime
/**
* Prevent user session closing
* (Code onTime)
* AzsaturnDx (2020) - No copyright at all
*
* Prevents the user from logging out by constantly refreshing userToken (re-logging-in according to: daf.js)
*
* REQUIRES: Your COT project must have the Account Manager enabled.
*/
var identities = $app.AccountManager.list();
var lastUser = identities._lastUser && identities[identities._lastUser];
var refreshInterval = 30;
refreshUsertokenLoop();
function refreshUsertokenLoop() {
setTimeout(function () {
$app.refreshUserToken(lastUser,
//Success Callback
(result) => {
console.log(result);
},
//Error Callback
(result) => {
console.log(result);
}
);
refreshUsertokenLoop();
}, refreshInterval * 1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment