I'm new in Angular and ionic and I build a native app for list messages, posts and more. I use the WordPress RESTApi with JWT Token. The token I store with @ionic/storage. After login I need to wait till the storage value is stored for an auth. API request as subscription. How I can wait till the storage value is setup and then make an http request?
Here is my code
usr = new BehaviorSubject(null);
constructor(private http: HttpClient, private storage: Storage, private plt: Platform, private router: Router) {
this.storage.create();
this.plt.ready().then(() => {
this.storage.get(JWT_KEY).then(data => { if(data){ this.usr.next(data) });
});
getUserValue() {
return this.user.getValue();
}
getAllMessages() {
let usr = this.getUserValue(); let url = usr['mainpath'];
let url = usr + '/app/v1/messages/all';
return this.http.get<any[]>(url).pipe(
map(data => {
return data;
})
);
}
When I call getAllMessages in a component they are not working because the storage value is not setup, but I can't use then() from storage to create a obs. http request?! Where I'm wrong?