Search code examples
amazon-web-servicesionic-frameworkionic3ionic4aws-amplify

AWS Amplify federated google login work properly on browser but dont work on Android


The issues are when I am trying to run federated authentication with the help of amplify auth method on the browser it works fine, but when I try to run it on my mobile.

It throws error No user found when I try to use Auth.currentSession() but the same work on the browser.

tried to search about this type of issue but I found related to ionic-cordova-google-plugin not related to AWS Amplify Federated Login Issue.

Updating the question after closing the question with less debugging information without asking for any information.

This is issues raised in git hub with respect to my problem.

  1. Issue No. 5351 amplify js it's still in open state.

https://github.com/aws-amplify/amplify-js/issues/5351

  1. Another issue 3537 which is still in Open

These two issues has the same scenario like me, I hope its enough debugging information, if more required mention comment instead of closing without notification, it's bullying for a beginner not helping


Solution

  • I fixed the above problem by referring a comment or wrapped around fix.

    Link that will take to that comment directly link to comment.

    • First read the above comment as it will give you overall idea of what exactly the issue is instead of directly jumping to the solution.
    • Once you read the comment you will be little unclear with respect to implementation as he has use capacitor and not every one are using capacitor.

    In my implementation I ignore this part as I am not using capacitor.

    App.addListener('appUrlOpen')
    
    • Now lets go to main step where we are fixing this issue, I am using deep links to redirect to my application
    this.platform.ready().then(() => {
          this.deeplinks
            .route({
              "/success.html": "success",
              "/logout.html": "logout",
            })
            .subscribe(
              (match: any) => {
                const fragment = JSON.stringify(match).split('"fragment":"')[1];
                 // this link can be your any link based on your requirement, 
                 // what I am doing it I am passing all the data which I get in my fragments.
                 // fragments consists of id_token, stage, code,response type.
                 // These need to be passed to Ionic in order for Amplify to run its magic.
                document.location.href = `http://192.168.1.162:8100/#${fragment}`;
              },
              (nomatch) => {
                console.log("Got a deeplink that didn't match", nomatch);
              }
            );
        });
    

    I got this idea by referring the issue in which the developer mentioned of sending code and state along with application deep linking URL.