I have created a lambda function and attached it as a pre and post login Trigger. I want this Lambda to triggered every time I am routed via AWS Cognito, not just logged in. Let me explain,
I have two App Clients:
App A -> Restricted
App B -> No Restrictions
User “john” tries to login to App A first. The Lambda trigger blocks him as it is a restricted group.
Lambda Code
const handler = async (event) => {
if (
event.userName === "john" && event.callerContext.clientId === "7hkgublahblah"
// Block this user from using App A
) {
throw new Error("This is a restricted Site.");
}
return event;
};
export { handler };
Faulty Sequence:
- John goes to App B Logs in and comes back to App A,
- App A Redirects John to Cognito,
- Since he is already logged into Cognito (has a live session as he went to App B via Cognito)
- He is allowed to access App A.
- The Lambda is NOT Triggered this time
.
I want to write a functionality that will trigger a Lambda every time a user is redirected from Cognito to the App. So I can block certain users even if they have a Live Session with AWS Cognito i.e. are logged into Cognito by accessing some other App.