簡體   English   中英

如何在放大中捕獲來自 aws cognito pre signup lambda 的錯誤?

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

我在 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
  }

您必須在 Pre-SignupTrigger(Lambda 函數)內部處理此錯誤

假設您使用 amplify 生成此設置 - 您可以在 Lambda 函數模板中本地執行此操作,您可以在文本編輯器中對其進行編輯。 該函數的代碼應位於amplify/backend/function/<functionname>

話雖如此,為了在默認 Amplify 實施之外更靈活地使用 Amazon Cognito,您可能需要考慮導入預先存在的 Amazon Cognito 用戶池: https : //docs.amplify.aws/cli/auth/import

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM