Q:

Ionic 5 fetch JWT an send header in HTTP calls using IonicStorage

I am porting an angular web app to Ionic and I am stuck.
Use case - I want to fetch the jwt token stored in IonicStorage as userAttributes and send it in post headers.
userAttributes = {name:"SomeName",token:**theJWTToken**}

Since IonicStorage returns promise I am unable to follow my previous flow. I am noob at Promises and Observables. Need some advice on how to fetch the token from IonicStorage into options variable and send it in http post.
Previously I used to do it as below 
login.service.ts
 getOptions(){
    let headers = new HttpHeaders({
      'X-AUTH-TOKEN': JSON.parse(localStorage.getItem('userAttributes')).token
    });
    let options = { headers: headers, withCredentials: true };
    return options;
  }

resetTokenLink(){
    var options = this.getOptions();
    return this.http.post(environment.APIBaseURL+"/resendToken",'',options);
  }

verifyMail.page.ts
 resend(){  
    this.loginService.resetTokenLink().subscribe(
      res => {this.showAlert("Success",res['msg'])},
      err => {this.showAlert("Error",err.error)}
    );
  }

A:

After going through multiple forms and blogs, I found a way to get this to work.
Solution:
I have created a HTTPInterceptor which intercepts all HTTP calls and adds it to the required header.
Interceptor.service.ts
import { Injectable } from '@angular/core';
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse, HttpErrorResponse } from '@angular/common/http';
import { Storage } from '@ionic/storage';

import { Observable,from } from 'rxjs';
import {  throwError } from 'rxjs';
import { AlertController } from '@ionic/angular';
import { map, catchError, switchMap } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class InterceptorService implements HttpInterceptor  {

  constructor(private alertController: AlertController, private storage: Storage) {}

  intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
      return from(this.storage.get('userAttributes'))
          .pipe(
              switchMap(token => {               
                  request = request.clone({ headers: request.headers.set('X-AUTH-TOKEN', token.token ) });
                  request = request.clone({ headers: request.headers.set('Content-Type', 'application/json') });
                  request = request.clone({ url:request.url });
                  return next.handle(request).pipe(
                      map((event: HttpEvent<any>) => {
                          if (event instanceof HttpResponse) {
                              // do nothing for now
                          }
                          return event;
                      }),
                      catchError((error: HttpErrorResponse) => {
                          const status =  error.status;
                          const reason = error && error.error.reason ? error.error.reason : '';

                          this.presentAlert(status, reason);
                          return throwError(error);
                      })
                  );
              })
          );

  }

  async presentAlert(status, reason) {
      const alert = await this.alertController.create({
          header: status + ' Error',
          subHeader: 'Subtitle',
          message: reason,
          buttons: ['OK']
      });

      await alert.present();
  }
}

add the interceptor to NGModule providers - app.modules.ts.
import { HttpClientModule ,HTTP_INTERCEPTORS} from '@angular/common/http';

.
.
other code
.
.

 providers: [
    StatusBar,
    SplashScreen,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
 --->   { provide: HTTP_INTERCEPTORS, useClass: InterceptorService, multi: true },

  ],

Done now all the requests will have the mentioned header.
Some references which helped: 
https://forum.ionicframework.com/t/ionic-4-storage-token-access-for-http-interceptor/158822 
https://ionicacademy.com/ionic-http-interceptor/

