Auth login basic not working after ionic build android --prod

I am using the following code to signin inside a provider:

 signIn(details): Promise<any[]>{
    return new Promise((resolve, reject) => {
      this.auth.login('basic', details).then(() => {
        resolve(someData);
      }, (err: any) => {
        reject(err);
      });
    });
  }

I have properly imported Auth at my provider constructor.
It works when I preview on browser and Ionic View, but triggers this error after install an apk generated by “ionic build android --prod”:

Error: Request has been terminated. Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is been unloaded, etc.

My internet connection is on.
Can anybody help me?

Sounds like a potential CORS issue, but there’s also no reason to explicitly instantiate a Promise here when you already have the one coming back from login. In fact, there’s virtually never any time you should need to instantiate Promises in app code.

1 Like

Thanks for the reply @rapropos. What do you suggest when I have to use an Observable inside a Promise? I want to isolate my provider methods from the pages. Here is an example of a provider method:

someMethod(): Promise<any>{
    return new Promise((resolve, reject) => {
      this.db.collection("database").fetch().subscribe((data) => {
          // some service logic...
         resolve(data);
      }, (err: any) => {
        reject(false);
      });
    });
  }

Inside my page component I just want to call:

this.someProvider.someMethod().then(data => {
    // page logic
});

Observable.toPromise().

1 Like