Skip to content

Cognito: Pre authentication Lambda not triggered for new users even if PreventUserExistenceErrors is set to ENABLED

0

Contrary to the API docs (https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-authentication.html) the Pre authentication Lambda is not triggered if a user doesn't exist, even if PreventUserExistenceErrors for my app client is set to ENABLED. I'm on the "Essentials" plan.

I had to replicate the pre-auth check in the pre-token lambda (throwing an error if the check fails) which shows up as an ugly CloudFront error page to the user but at least I can deny access for new users that way (pre-auth will then kick in on the second auth attempt, i.e. after log out / re-login).

asked 10 months ago121 views

2 Answers
0

The Pre Authentication Lambda trigger is not executed when a user does not exist, except in cases where the PreventUserExistenceErrors setting is enabled for the associated app client. However, even with this configuration enabled, the trigger is invoked solely during authentication attempts for valid, existing users. Authentication requests for non-existent users continue to bypass the pre-authentication Lambda.

https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-authentication.html

EXPERT

answered 10 months ago

0

Thank you for the quick reply! I've read it carefully, but still don't understand how a user can be both "valid and existing" and be "non-existing" at the same time? In my case, I've setup a social login (via Google) where on first login, the user is created in the user pool but does not (yet) trigger the Pre Authentication Lambda, so will be forwarded to the app without any checks.

answered 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.