Search code examples
amazon-web-servicesoauthgoogle-oauthamazon-cognitoaws-amplify

Retrieve user's name and email after aws-amplify federated login with Google


I am using aws-amplify to log my users into my site. I'm using

Auth.federatedSignIn({provider: 'Google'});

to log them in. When they click through with their email, they are added to a user pool where their username looks something like

Google_12345678901234567890

and their email and name are inside the profile when you click on that Google username in the user pool. How can I access the user's name and email through my Angular code?

I've tried

Auth.currentAuthenticatedUser()

and

Auth.currentSession()

both of which don't hold that info, along with Auth.currentUserInfo() which returns empty, and

Auth.userAttributes()

which doesn't seem to work. Any ideas would be greatly appreciated. Thank you!


Solution

  • I kinda answered my own question. After authenticating with

    Auth.federatedSignIn({provider: 'Google'});
    

    I ran the following code:

    Auth.currentSession()
        .then(data => {
            let idToken = data.getIdToken();
            console.dir(idToken);
            let email = idToken.payload.email;
            console.log(email);
        })
        .catch(err => console.log(err));
    

    All the info sits in the id token and can be viewed through

    console.dir(idToken);