title: Session timeout in Angular if user is idle in canActivate function of AuthGuard
body: <p>Currently in the application if user is not authenticated then he cannot proceed to any routes but if he/she is authenticated then navigation is possible. This is implemented through canActivate function in auth guard. If I want to have a session timeout as well if user is idle suppose after 5 minutes, then what is the way of achieving that through canActivate function and Auth-Guard?</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
  
  @Injectable()
   export class AuthGuard implements CanActivate {
  
  constructor(private router: Router) { }
  
  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
      if (sessionStorage.getItem('currentUser')) {
          // logged in so return true
          return true;
      }
  
      // not logged in so redirect to login page with the return url
      this.router.navigate(['/'], { queryParams: { returnUrl: state.url }});
      return false;
  }
  }
  </code></pre>