首页 > 解决方案 > 如何在放大中捕获来自 aws cognito pre signup lambda 的错误?

问题描述

我在 cognito 中使用预注册 lambda 触发器。某些情况下的 pre singup lambda 会引发异常(期望行为)。前端有以下代码:

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

当我运行代码时,我总是在 console.log 中看到成功消息( d 未定义),紧随其后,我还看到以下消息:来自放大的控制台日志错误 我想了解如何捕获此错误,我猜想放大记录它我,但我怎么能抓住它?

下面附上我的放大配置:

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
  }

标签: javascriptvue.jsamazon-cognito

解决方案


您必须在 Pre-SignupTrigger(Lambda 函数)中处理此错误

假设您使用 amplify 生成了此设置 - 您可以在 Lambda 函数模板中本地执行此操作,您可以在文本编辑器中对其进行编辑。该函数的代码应位于amplify/backend/function/<functionname>

话虽如此,为了在默认 Amplify 实施之外更灵活地使用 Amazon Cognito,您可能需要考虑导入预先存在的 Amazon Cognito 用户池:https ://docs.amplify.aws/cli/auth/import


推荐阅读