HttpInterceptorExpander

Expands:

$applicationRoot.directory$/native/ionic/src/app/services/http-interceptor.service.ts

if:

true
property value
element type ApplicationInstance
qualified name net.democritus.expander.ionic.applicationinstance.service.HttpInterceptorExpander
layer ROOT
technology COMMON
sourceType JS
phase expansion
features  

Example

Some example of the content generated by the expander:

import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
import { Storage } from '@ionic/storage';
import { Observable, from } from 'rxjs';
import { mergeMap } from 'rxjs/operators';


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

  constructor(
    private storage: Storage
  ) { }

  intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    const promise = this.storage.get('euRent_USER_INFO');
    return from(promise).pipe(
      mergeMap(user => next.handle(this.addToken(request, user)))
    ) as Observable<HttpEvent<any>>;
  }

  addToken(request: HttpRequest<any>, user: any) {
    if (user && request.url.includes('euRent')) {
      const clone: HttpRequest<any> = request.clone({
        setHeaders: { Authorization: user.token }
      });
      return clone;
    }
    return request;
  }

}