I've been looking for a tutorial on how to get some values I have on my Capacitor Storage in Ionic 6 and use them before doing the HTTP request.
Example method in cart.service.ts:
getCart() {
Storage.get({ key: 'token' }).then( response => {
this.token = JSON.parse(response.value);
});
return this.http.get<Product[]>(this.token.api_route + 'user/cart');
}
What I want to call on onInit:
this.cartService.getCart().subscribe(response => {
this.products = response;
});
So the main problem is that token is null because getting it from storage is async. How can I solve that problem? And get the token.api_route before doing HTTP call?