跳至內容

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 年前檢視次數 249 次
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.
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。