title: Angular HttpInterceptor does not work with the first request after login
body: <p>I spend 2 days with this problem, I could not find any solution.</p>
  
  <p>I am facing a problem with <strong>angular HTTP interceptor</strong> in an Ionic 4 project.</p>
  
  <p>After login success, the router navigates to the home page and call some API with a token.</p>
  
  <p>When login succeeds, I store the token to the localStorage and use this token in HTTP interceptor,
  In the home page the first time, the token was not set into authorization header.</p>
  
  <p>If I refresh the application, then it works fine,
  Here I attached my code snippet below.</p>
  
  <p><strong>HTTP INTERCEPTOR:</strong></p>
  
  <pre><code>    intercept(httpReq: HttpRequest&lt;any&gt;, next: HttpHandler): Observable&lt;HttpEvent&lt;any&gt;&gt; {
          if (localStorage.getItem('tokenKey')) {
              const token = localStorage.getItem('tokenKey');
              const req = httpReq.clone({
                  setHeaders: {
                      'Authorization': 'Bearer ' + token,
                      'Content-Type': 'application/json'
                  }
              });
              return next.handle(req);
          } else {
              const req = httpReq.clone({
                  headers: httpReq.headers.set('Content-Type', 'application/json'),
              });
              return next.handle(req);
          }
  }
  </code></pre>
  
  <p><strong>Here Is my login component code</strong></p>
  
  <pre><code> login() {
      this.authService.login(this.user)
          .then((data: any) =&gt; {
              this.events.publish('user:created', data.profile);
              this.events.publish('token:created', data.token);
              if (data.token) {
               this.router.navigate(['home']);
            }
        }).catch(error =&gt; {
           this.presentAlert(error);
        });
  }
  </code></pre>
  
  <p><strong>Here is login service code:</strong></p>
  
  <pre><code>login(user) {
  return new Promise((resolve, reject) =&gt; {
      this.http.post(ApiEndPoint + 'signin/index', user).subscribe((data: any) =&gt; {
          localStorage.setItem('tokenKey', data.data.token);
          this.authState.next(true);
          resolve(data.data);
      }, err =&gt; {
          reject(err);
      });
  });}
  </code></pre>