Amplify-js: Catch Error during federatedSignIn (handleAuthResponse) in Angular

Created on 1 Nov 2019  路  4Comments  路  Source: aws-amplify/amplify-js

* Which Category is your question related to? *
Auth
* What AWS Services are you utilizing? *
Cognito
* Provide additional details e.g. code snippets *

I am using Amplify within Angular.
I have implemented a pre-sign up hook that declines certain users. When this hook is triggered during the federatedSignIn flow it redirects to google/facebook and then on the return the url is:
http://localhost:4200/auth-return?error_description=PreSignUp%20failed%20with%20error%cognito_presignup_custom_error.%20&state=state_code&error=invalid_request

And I have the following error message:
Unhandled Promise rejection: PreSignUp+failed+with+error+cognito_presignup_custom_error.+ ; Zone: ; Task: Promise.then ; Value: Error: PreSignUp+failed+with+error+cognito_presignup_custom_error.+
at OAuth. (OAuth.js:201)
at step (OAuth.js:52)
at Object.next (OAuth.js:33)
at OAuth.js:27
at new ZoneAwarePromise (zone-evergreen.js:876)
at push../node_modules/@aws-amplify/auth/lib/OAuth/OAuth.js.__awaiter (OAuth.js:23)
at OAuth.push../node_modules/@aws-amplify/auth/lib/OAuth/OAuth.js.OAuth.handleAuthResponse (OAuth.js:181)
at AuthClass. (Auth.js:1631)
at step (Auth.js:44)
at Object.next (Auth.js:25) Error: PreSignUp+failed+with+error+cognito_presignup_custom_error.+
at OAuth. (http://localhost:4200/vendor.js:111247:35)
at step (http://localhost:4200/vendor.js:111098:23)
at Object.next (http://localhost:4200/vendor.js:111079:53)
at http://localhost:4200/vendor.js:111073:71
at new ZoneAwarePromise (http://localhost:4200/polyfills.js:3920:29)
at push../node_modules/@aws-amplify/auth/lib/OAuth/OAuth.js.__awaiter (http://localhost:4200/vendor.js:111069:12)
at OAuth.push../node_modules/@aws-amplify/auth/lib/OAuth/OAuth.js.OAuth.handleAuthResponse (http://localhost:4200/vendor.js:111227:16)
at AuthClass. (http://localhost:4200/vendor.js:110809:65)
at step (http://localhost:4200/vendor.js:109222:23)
at Object.next (http://localhost:4200/vendor.js:109203:53)

Any thoughts on how I can catch this error?

Angular Auth question

Most helpful comment

Same problem in angular. I've tried lots of different configurations and still not able to make it work.

All 4 comments

I'm having the exact same problem in React.

Same problem in angular. I've tried lots of different configurations and still not able to make it work.

Wow, no answers? :(

Apparently you can catch the error with Hub.listen, but you have to register the callback before the Auth module processes the result from the redirect. Calling Hub.listen before Amplify.configure and logging the payload I got this in the console:

{
  "event":"parsingCallbackUrl",
  "data":{
    "url":"http://localhost:19006/dash/?error_description=PreSignUp+failed+with+error+LINKED_EXTERNAL_USER%3A+Google.+&state=KustOP4fqhIPA9ckz226D9Qk7Wt27zr5&error=invalid_request"
  },
  "message":"The callback url is being parsed"
}

[ERROR] 19:26.131 OAuth - Error handling auth response. Error: PreSignUp+failed+with+error+LINKED_EXTERNAL_USER%3A+Google.+
    at OAuth.<anonymous> (OAuth.js:236)
    at step (OAuth.js:55)
    at Object.next (OAuth.js:36)
    at OAuth.js:30
    ...

{
  "event":"configured",
  "data": null,
  "message":"The Auth category has been configured successfully"
}

{
  "event":"signIn_failure",
  "data":{ // Error object
    message: "PreSignUp+failed+with+error+LINKED_EXTERNAL_USER%3A+Google.+",
    stack: "Error: PreSignUp+failed+with+error+LINKED_EXTERNAL_USER%3A+Google..."
  },
  "message":"The OAuth response flow failed"
}

{
  "event":"cognitoHostedUI_failure",
  "data":{ // Error object
    message: "PreSignUp+failed+with+error+LINKED_EXTERNAL_USER%3A+Google.+",
    stack: "Error: PreSignUp+failed+with+error+LINKED_EXTERNAL_USER%3A+Google..."
  },
  "message":"A failure occurred when returning to the Cognito Hosted UI"
}

{
  "event":"customState_failure",
  "data":{ // Error object
    message: "PreSignUp+failed+with+error+LINKED_EXTERNAL_USER%3A+Google.+",
    stack: "Error: PreSignUp+failed+with+error+LINKED_EXTERNAL_USER%3A+Google..."
  },
  "message":"A failure occurred when returning state"
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

romainquellec picture romainquellec  路  3Comments

josoroma picture josoroma  路  3Comments

shinnapatthesix picture shinnapatthesix  路  3Comments

DougWoodCDS picture DougWoodCDS  路  3Comments

rygo6 picture rygo6  路  3Comments