Managing User Types and Assigning User Groups with Cognito

0

Hello Guys,

We are currently developing an application with two main user categories. We have 2 separate front-end applications built for 2 user categories Our front end is built using Next.js, and our back end is serverless (Lambda/nodejs). We are using the Cognito user pool for user authentication.

We allow users to sign in using Google, Apple, and email. Upon sign-up, we need a way to assign each user to a specific user group. The challenge we're facing is finding a method to pass each user's user type to the back-end so that it can handle Cognito Lambda triggers or Cognito APIs to add users to their respective groups. Specifically, we are looking for a way to pass custom parameters to the back end and access them when users sign up using Google or email.

Is there a way where we can pass user type from the FE to the BE during user signup using Google or email and then add users to the respective user group?

Thanks in advance.

1 Answer
0

Hello,

You can use custom attributes when a user signs up. You can use one to store the user type. You can then capture that during sign-up using the Pre-Signup Lambda Trigger - https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-sign-up.html

In combination with that you can use the Post-Authentication or Pre-Token Generation Lambda triggers to assign users to the correct group after they sign in with Google or Apple. These triggers allow you to evaluate the user’s type once they have successfully authenticated, and based on this, you can assign them to the appropriate group using the Cognito API AdminAddUserToGroup. This ensures that users are placed into the correct group after sign-in, based on their attributes or context.

Reference Links:

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

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

https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminAddUserToGroup.html

AWS
answered 2 months ago
profile picture
EXPERT
reviewed 2 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.

Guidelines for Answering Questions