JS - autoLogout function

0 votes
129 views
added Oct 25, 2019 in Javascript by LC Marshal Captain (25,770 points)
autoLogout(){
  this.interval = setInterval(()=> {
    let logoutTime = store.state.login.logout_time;
    let warning_flag = false;
    if(logoutTime == null && store.state.login.token != null) {
      warning_flag = true;
    }
    else if(logoutTime != null && store.state.login.token != null){
      // method to be executed;
      var now = moment(new Date()); //todays date
      var end = logoutTime; // another date
      var duration = moment.duration(now.diff(end));
      var days = duration.asDays();
      //console.log(days)
      //console.log("Login data is:",logoutTime);
      if(days >= 7){
        warning_flag = true;
      }
    }
    if(warning_flag){
      this.$swal({
          title: "Oops",
          text: "You have been logged out, please login again.",
          icon: "warning"
        }).then(() => {
            this.logout();
        })
    }
  }, 5000); // 5seconds    
}

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...