Usama Ahmed
Usama Ahmed

Reputation: 93

Admin and super admin Authorization and conditional rendering using AWS Amplify + React app

I am working on Amplify + React fullstack app and have created complete Authentication flow. I want to authorize users based on their roles i.e. admin, superadmin, user, etc. When I sign up a new user, I am seeing the details in AWS Cognito but I am not able to figure out the roles for the user. I have two solutions in mind.

  1. Add a userType custom attribute in User table in AWS Cognito.
  2. Create three different groups in the pool and handle them manually.

I want to know which solution is better. I am unable to find any help online so it would be great if the detailed steps are shared. Thanks in advance.

Upvotes: 1

Views: 825

Answers (1)

Anurag
Anurag

Reputation: 163

cognito groups are meant for exact same use cases. you can create a group named ADMIN and in your client you may check if the signed in user is part of ADMIN group like this

user.signInUserSession.accessToken.payload["cognito:groups"]?.includes("ADMIN")

Upvotes: 2

Related Questions