Denying a Sign-up request in Cognito User Pools

百般思念 提交于 2019-12-12 10:36:08

问题


The description of a Cognito User Pools Pre Sign-up Lambda Trigger is:

This trigger is invoked when a user submits their information to sign up, allowing you to perform custom validation to accept or deny the sign up request.

I want to deny a sign-up request based on a certain condition in my Lambda. The trigger parameters (reproduced from the docs below) seem to only support auto-verification and auto-confirmation:

{
    "request": {
        "userAttributes": {
            "string": "string",
            ....
        },
        "validationData": {
            "string": "string",
            "string": "string",
             ....
        }
    },

    "response": {
        "autoConfirmUser": "boolean",
        "autoVerifyPhone": "boolean",
        "autoVerifyEmail": "boolean"
    }
}

How can I accept or deny a sign-up request based on the outcome of the Pre Sign-up Lambda Trigger?


回答1:


You can return a empty dict from the lambda to deny sign up request. Similarly you return the event value itself to accept the sign up request.

def lambda_handler(event, context):
    if denySignUp:
        return {}
    else:
        return event



回答2:


Alternatively, you can also deny signup by throwing an exception, as shown here.

The exception message will be passed back to Cognito, and on to the client, in the form of a validation error with the message PreSignUp failed with error {exceptionMessage}..



来源:https://stackoverflow.com/questions/50661422/denying-a-sign-up-request-in-cognito-user-pools

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!