Skip to content

Instantly share code, notes, and snippets.

@SumanaMalkapuram
Last active January 29, 2020 22:52
Show Gist options
  • Save SumanaMalkapuram/b53a6985029dcc2543139074a2290863 to your computer and use it in GitHub Desktop.
Save SumanaMalkapuram/b53a6985029dcc2543139074a2290863 to your computer and use it in GitHub Desktop.
Skip rule for silent Auth
function(user, context, callback) {
let timeLimitMs = 1000;
let currentDate = new Date();
let currentTimeMs = currentDate.getTime();
let last_auth_time = new Date(context.authentication.methods.find((method) => method.name === 'pwd').timestamp);
let lastAuthTimeMs = last_auth_time.getTime();
const isSilentAuth = currentTimeMs - lastAuthTimeMs > timeLimitMs ? true : false;
console.log("current time", currentTimeMs);
console.log("lastAuthTime", lastAuthTimeMs);
console.log("difference", isSilentAuth);
console.log("auth methods", context.authentication.methods);
if (!isSilentAuth) {
// bla bla logic to post to APIs
console.log("not silent", context);
callback(null, user, context);
} else {
console.log("in silent and not posting to API", context);
callback(null, user, context);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment