Ionic + Capacitor on IOS does not redirect to app after success login

Hello,

I have an angular ionic application. When I run the application in the browser, the login works fine.

But when I try to run this application using xcode on ipad simulator, the login is not working right. After successful login, I am seeing this error ‘Failed to Fetch’. Currently the app is not published to appstore and I am trying to make it work locally.

I also added url type in xcode Identifier field and the URL SCHEME field

I followed this tutorial Auth0 Ionic & Capacitor (Angular) SDK Quickstarts: Login

Here is my app.component.ts
ngOnInit(): void {
console.log(‘CALLBACKURL’);
console.log(‘-----------------------’)
console.log(callbackUri);

// Use Capacitor's App plugin to subscribe to the `appUrlOpen` event
App.addListener('appUrlOpen', ({ url }) => {
  // Must run inside an NgZone for Angular to pick up the changes
  // https://capacitorjs.com/docs/guides/angular

  this.ngZone.run(() => {
    if (url?.startsWith(callbackUri)) {
      // If the URL is an authentication callback URL..
      if (
        url.includes('state=') &&
        (url.includes('error=') || url.includes('code='))
      ) {
        // Call handleRedirectCallback and close the browser
        this.auth
          .handleRedirectCallback(url)
          .pipe(mergeMap(() => Browser.close()))
          .subscribe(value => {

          }, error => {
            console.log('ERROR' + error);
          });
      } else {
        Browser.close();
      }
    }
  });
});

}

1 Like

Did you ever find a solution? I’m having the same issue with the same setup