Multiple User types and Identity

Viewed 135

In my project, I am currently working on user roles (claims) and registration.

I am struggling with which approach I should use or if there is any source I can base on. I have two types of application users (related to the app's domain), let's say they are Lecturer and Student, these entities differ by a few fields so I wanted to have them separated.

How should I design the entities now?

There are a few cases but I'm not sure how to cover them.

User can be Lecturer

User can be Student

User can be both Lecturer and Student (at the same time)

How do I manage that?

I was thinking about adding a foreign key to each entity (Lecturer/Student/AnyOtherType) to reference IdentityUser and during the registration define the type of user by claims

userIdentity.AddClaim(new Claim(ClaimTypes.Role, "Lecturer"))
userIdentity.AddClaim(new Claim(ClaimTypes.Role, "Student"));

Do you think it is a good idea? How to handle incoming requests based on user role? I know I can use something similar to the following example in some Services, but ideally, I would like to avoid unnecessary calls to the DB just to filter out the needed data in the Service

user.IsInRole("lecturer")

I'm focusing on DDD rn.

0 Answers
Related