'Why ionic set storage function always called first before api response?

While debugging on android studio I found out that the storage.set was called first before the api response in result the value that is set to storage become null.

this.http.post(`${environment.api_url}login`,form.value).subscribe(
  (res:any)=>{
    console.log(res.token);
    this.storage.set('customerLogin', res);
    this.storage.set('customerToken', res?.token)
    return;
    ...
}

Also I tried to remove the async on the storage service set function but still the function will return first before the api response. And now I don't know what else I could do to make the set storage function called after api response.

this is the set function on storage service

async set(key: string, value: any) {
  const encryptedData = btoa(escape(JSON.stringify(value)));
  return await this.storage.set(key, encryptedData)
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source