Ionic 3: Ionic Storage with Observables

#1

Hey Ionites!

I have CustomerPage, CustomerService and AuthService.

In need to pass an access_token from AuthService to CustomerService for http-get request.
AuthService and CustomerService are not working(see comments).
Please help me :slight_smile:

CustomerPage:

this.customerService.getCustomersDashboard()
      .subscribe(....)

CustomerService:

getCustomersDashboard(): Observable<any> {
      var url = "......";
    let authHeader = this.authservice.getAuthHeaders();  // HttpHeader with access_token

    return this.http.get(url, { headers: authHeader }).pipe(
      map((resp: Response) => {
        let response = this.extractData(resp);
        return response;
      }));

AuthService:
** is not working !!!**

 getAuthHeaders(){
    const authtoken = Observable.fromPromise(this.storage.get(`access_token`));
   
    return new HttpHeaders({ 'authorization': authtoken });  // => **not working**
  }
#2

try the following:

  getAuthHeaders(){
    this.storage.get(`access_token`).then( res => {
      return new HttpHeaders({ 'authorization': res });
    })
  }
#3

I have already tried, You cannot return inside “then”, getAuthHeaders() now returns void.