title: Ionic 3 Wait for storage promise to completely finish before running function
body: <p>I’m trying to get data from the server using token from ionic storage. The problem I’m experiencing is when the get token promise can’t retrieve the token on time. Therefore, whenever I reload or reopen the app it sometimes return with an unauthorized error. </p>
  
  <p><strong>dashboard-service.ts</strong></p>
  
  <pre><code>authUrl = "https://sampleapi.herokuapp.com"
  authHeaders;
  
  getToken() {
  this.storage.get('token').then((token) =&gt; {
    console.log('Bearer ' + token);
    this.authHeaders = {
      headers: new HttpHeaders({
        'Accept': 'application/json',
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + token
      })
  }
  });
  }
  
  getInfo(): Observable&lt;Info&gt; {
  return this.http.get&lt;Info&gt;(this.authUrl + '/api/users/info', this.authHeaders).pipe(
    catchError(this.handleError)
  );
  }
  </code></pre>
  
  <p><strong>dashboard.ts</strong></p>
  
  <pre><code>ionViewDidLoad() {
  this._dashboardService.getToken();
  this._dashboardService.getInfo().subscribe(
    info =&gt; {
      console.log('USER INFO: ' + info);
      this.info = info
    },
    error =&gt; {
      console.log('INFO ERROR: ' + error);
    }
  );
  }
  </code></pre>