내용으로 건너뛰기

Can I throw custom error message from pre authentication trigger lambda and display the error message on Hosted UI sign in page?

0

I want to throw custom error message which is thrown from pre authentication and display it on hosted UI sign in page.

# sample code inside pre authentication lambda trigger
# Increment counter or block user
        failed_attempts += 1
        if failed_attempts > 10:
            raise Exception('User is blocked due to repeated failed login attempts.')

Goal: Display User is blocked due to repeated failed login attempts on hosted UI sign in page.

Is this possible?

1개 답변
0

Unfortunately, it is not possible to directly display a custom error message from the pre-authentication Lambda trigger on the Cognito hosted UI sign-in page. However, there are a few alternative approaches you can consider:

  1. Use a custom UI instead of the hosted UI. With a custom UI, you have full control over error message display and can integrate directly with Cognito APIs to handle authentication and error scenarios.
  2. Implement a custom error page. You can configure Cognito to redirect to a custom error page when authentication fails. On this page, you can implement logic to check for specific error conditions and display appropriate messages.
  3. Use the post-authentication trigger in combination with pre-authentication. In the pre-authentication trigger, you can set a custom attribute on the user to indicate they are blocked. Then, in the post-authentication trigger, you can check this attribute and deny access if necessary. This approach allows you to use Cognito's built-in error handling for denied access.
  4. Leverage Cognito's built-in account locking feature instead of implementing it in Lambda. Cognito can automatically lock accounts after a specified number of failed attempts, which will display a more user-friendly message on the hosted UI.
  5. Cognito does allow some level of error message customization through the AWS Console or API. You might be able to repurpose an existing error message to fit your needs.
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

관련 콘텐츠