title: Logout User and Redirect User to Login on Token Expiration - Angular 8
body: <p>I receive <code>idToken</code> and I am also getting the expiration time <code>expTime</code> in timestamp format eg: <code>1605803717</code> which basically expires in 1 day. I want to log the user out and redirect the user to login page if <code>idToken</code> expires. I have implemented a HTTPInterceptor as below:</p>
  <pre><code>intercept(
    request: HttpRequest&lt;any&gt;,
    next: HttpHandler
  ): Observable&lt;HttpEvent&lt;any&gt;&gt; {
    this.token = JSON.parse(localStorage.getItem(&quot;getToken&quot;));
    if (this.tokenExpired(this.token)) {
      Auth.signOut().then((res) =&gt; {
        this.authState === &quot;signedout&quot;;
        this.router.navigate([&quot;/login&quot;]);
      });
    } else {
      return;
    }
  }
  
  private tokenExpired(token: number) {
    const expiry = token;
    return Math.floor(new Date().getTime() / 1000) &gt;= expiry;
  }
  
  </code></pre>
  <p>My question is to know if this implementation will work automatically I mean, will this interceptor automatically be triggered when <code>idToken</code> expires or do I need to setup some kind of trigger? How does HTTPInterceptors work? Will it be able to catch time expiration and logout user or I have to implement something else to catch <code>idToken</code> expiration?</p>