How to catch an error coming from aws cognito pre signup lambda in amplify?

Viewed 606

I am using the pre signup lambda trigger in cognito. The pre singup lambda for some cases rasie an exception(desire behaviour). front-end side have the following code:

await Vue.prototype.$auth
          .federatedSignIn({
            provider: provider
          }).then((d) => {
            console.log('success ', d)
          }).catch((e) => {
            console.log('here is and error', e)
          })
      }

When I run the code I always see the success msg ( d is undefined) in the console.log, right after it I see as well the following msg:console log error from amplify I miss to understand how can I catch this error, I guess amplify log it for me, but how can i catch it?

bellow attach my amplify configuration:

import Amplify, { Auth } from 'aws-amplify'

export default {
  install (Vue) {
    Amplify.configure({
      Auth: {
        region: config.auth.region,
        userPoolId: config.auth.cognitoUserPoolId,
        userPoolWebClientId: config.auth.cognitoClientId,
        cookieStorage: {
          domain: config.auth.cognitoCookieStorageDomain,
          secure: config.auth.cognitoCookieStorageSecure
        },
        mandatorySignIn: false,
        authenticationFlowType: 'USER_SRP_AUTH',
        oauth: {
          domain: config.auth.cognitoDomain,
          scope: ['email', 'openid', 'aws.cognito.signin.user.admin'],
          redirectSignIn: config.auth.cognitoSignInRedirectUrl,
          redirectSignOut: config.auth.cognitoSignOutRedirectUrl,
          responseType: 'code' // or 'token', note that REFRESH token will only be generated when the responseType is code
        }
      }
    })
    Vue.prototype.$auth = Auth
  }
1 Answers

You have to handle this error inside of the Pre-SignupTrigger (Lambda Function)

Supposing you generated this setup with amplify - you can do this locally in the Lambda function template, which you can edit in your text editor. The code for the function should be located at amplify/backend/function/<functionname>

With that said, for more flexibility in using Amazon Cognito outside of the default Amplify implementations you may want to consider instead importing pre-existing Amazon Cognito User Pools: https://docs.amplify.aws/cli/auth/import

Related