I'm currently migrating my DB based user directory to AWS Cognito. I'm using migration
trigger for migrating existing users. This working fine.
My issue, What if an existing email id is used for SignUp
. So I thought to add PreSignUp
trigger which checks user exists in DB and also make auto confirmation for all users.
My question is how can I make a response from trigger when a User exists ?
What kinda JSON object the cognito is expecting, So that in client side it gives UserExistsException
.?
Draft Code.
def handler(event, context):
event['response']['autoConfirmUser'] = True
if event['request']['userAttributes']['email'] is not None:
if not user_exists(event['request']['userAttributes']['email']):
event['response']['autoVerifyEmail'] = True
else:
return #Validation Error response
return event
In AWS Cognito it automatically detects and throws an exception when someone tries to register with an existing email address. Therefore you can trigger the exception throwing out from Cognito and do the handling. So that from my opinion it is better to first check the user is exists in your DB and throw a custom exception without proceeding in to Cognito.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With