amplify-js: Error in Auth.js running the withOAuth example

Describe the bug I’m trying to follow the React Components example, using the withOAuth component (https://aws-amplify.github.io/docs/js/authentication#react-components). The first thing is that I had to change the code to make it compile. I’ve neede to change the class definition to

class App extends Component<{}, { authState: string, authData:any, authError:any }> {

The second thing, is that when I run the example, everything looks like is running correctly but I see the following error in the console:

Auth.js:2202 Uncaught (in promise) TypeError: Cannot read property 'accessToken' of undefined

Taking a look at the code, this is where it fails:

_a = _b.sent(), accessToken = _a.accessToken, idToken = _a.idToken, refreshToken = _a.refreshToken;

because _a is undefined. I guess this can have implications if I then try to make some calls using Amplify.

I’m having this error using a Cognito User Pool and google as authenticator.

To Reproduce Steps to reproduce the behavior: With a react app and a Cognito User Pool configured, configure Amplify using:

const awsmobile = {
    "aws_project_region": "eu-west-1",
    "aws_cognito_region": "eu-west-1",
    "aws_user_pools_id": "<theuserpoolid>",
    "aws_user_pools_web_client_id": "<theclientid>",
    "oauth": {
        "domain": "<yourclient>.auth.eu-west-1.amazoncognito.com",
        "scope": [
            "email",
            "openid"
        ],
        "redirectSignIn": "http://localhost:3000/",
        "redirectSignOut": "http://localhost:3000/",
        "responseType": "code"
    },
    "federationTarget": "GOOGLE"
};

Configure Auth using the following object:

const oauth = {
  domain: '<yourcognitouserpooldomain>.auth.eu-west-1.amazoncognito.com',
  scope: ['email', 'openid'],
  redirectSignIn: 'http://localhost:3000/',
  redirectSignOut: 'http://localhost:3000/',
  responseType: 'token'
};

Expected behavior I expect to see no errors in the console.

Desktop (please complete the following information):

  • OS: macOS Mojave, v 10.14.5
  • Browser: chrome, v 74.0.3729.169

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 5
  • Comments: 26 (8 by maintainers)

Most upvoted comments

Same error, please reopen.

I’ve a Cognito PreSignup trigger, when i send back a deny with custom message, cognito hosted UI correctly redirects to /myRedirectSignIn?error_description=PreSignUp+failed+with+error+CUSTOM.+&state=v95U7XDI5NKdsLOY7vPfnWPjYK2fVQj0&error=invalid_request

As soon as the page is starting to load, before everything on app side (HUB listners, etc), the error throws up: Unhandled Rejection (TypeError): _a is undefined

  • amazon-cognito-identity-js: 3.2.0
  • aws-amplify: 2.2.0
  • aws-amplify-react-native: 2.2.3

This is the console log:

[ERROR] 13:18.573 OAuth - Error handling auth response. Error: “PreSignUp+failed+with+error+social-login-missing-email.+” handleAuthResponse OAuth.ts:212 step 0.chunk.js:4345 verb 0.chunk.js:4276 __awaiter 0.chunk.js:4248 __awaiter 0.chunk.js:4227 handleAuthResponse 0.chunk.js:4551 _handleAuthResponse Auth.ts:1821 step 0.chunk.js:1779 verb 0.chunk.js:1710 __awaiter 0.chunk.js:1682 __awaiter 0.chunk.js:1661 _handleAuthResponse 0.chunk.js:3850 configure Auth.ts:229 default urlListener.ts:19 configure Auth.ts:228 configure Amplify.ts:43 configure Amplify.ts:42 App App.js:18 React 13 renderApplication renderApplication.js:21 run index.js:49 runApplication index.js:89 js index.js:7 Webpack 7 index.js:1 [DEBUG] 13:18.616 AuthClass - getting current authenticated user ConsoleLogger.ts:91 [DEBUG] 13:18.624 AuthClass - Error in cognito hosted auth response TypeError: “_a is undefined” _handleAuthResponse Auth.ts:1816 step 0.chunk.js:1779 verb 0.chunk.js:1710 fulfilled 0.chunk.js:1664 ConsoleLogger.ts:99 [DEBUG] 13:18.624 Hub - Dispatching to auth with
Object { event: “signIn_failure”, data: TypeError, message: “The OAuth response flow failed” } ConsoleLogger.ts:99 [DEBUG] 13:18.624 Hub - Dispatching to auth with
Object { event: “signIn_failure”, data: TypeError, message: “The OAuth response flow failed” } ConsoleLogger.ts:99 [DEBUG] 13:18.626 Hub - Dispatching to auth with
Object { event: “cognitoHostedUI_failure”, data: TypeError, message: “A failure occurred when returning to the Cognito Hosted UI” } ConsoleLogger.ts:99 [DEBUG] 13:18.627 Hub - Dispatching to auth with
Object { event: “cognitoHostedUI_failure”, data: TypeError, message: “A failure occurred when returning to the Cognito Hosted UI” } ConsoleLogger.ts:99 [DEBUG] 13:18.652 Hub - Dispatching to auth with
Object { event: “customState_failure”, data: TypeError, message: “A failure occurred when returning state” } ConsoleLogger.ts:99 [DEBUG] 13:18.653 Hub - Dispatching to auth with
Object { event: “customState_failure”, data: TypeError, message: “A failure occurred when returning state” } ConsoleLogger.ts:99 [DEBUG] 13:18.655 AuthClass - cannot load federated user from auth storage ConsoleLogger.ts:91 [DEBUG] 13:18.655 AuthClass - get current authenticated userpool user ConsoleLogger.ts:91 [DEBUG] 13:18.656 AuthClass - Failed to get user from user pool ConsoleLogger.ts:91 [DEBUG] 13:18.657 AuthClass - The user is not authenticated by the error No current user ConsoleLogger.ts:99