Ionic/Angular - retrieve token from storage and append to url

121 Views Asked by At

I store authToken in ionic storage, whose get method is async. When I make http request, I need to get this token from storage and append to request as url param. What I tried is :

getUsers(): Observable<any> {
    this.storage.get('authToken').then((token) => {
      return this.http.get(`${API_URL}/users?token=${token}`);
    });
  }

In Angular, http service returns Observable, that's why I put getUsers(): Observable<any> but it raises error a function whose declared type is neither void nor any must return a value...

How to deal ionic's asynchronous get method generally? Http interceptor came on my mind, to get this token from storage and append it to every request except where route is /login and /register, but I don't know how to implement it.

0

There are 0 best solutions below