What if I don't implement my own identity solution but use a third party service like auth0?
This is the dilemma that we all must face when designing a new system. It doesn't really matter if you are using DDD or other modelling patterns, if this is a real system that you want to integrate with the evolving industry then you will find that the most flexible model will abstract the concepts of Identity, Authentication and Authorization separately.
While and Employee can log in, should all things that login be Employees? For that matter are all things that login even Users?
Conceptually, Employee is a time constrained Role. You as a person will assume the role of Employee for many different Employers over your journey, you will also be a user of many systems without actually being an employee. Some of the time frames may overlap, each of those roles will have specific security roles that will govern the Authorization or Access that you have to the system. You might use a number of different trusted credentials linked to your Identity that can be used to Authenticate.
In the case of a Supervisor, this could simply be a security role assigned to a specific Employee, unless you have additional metadata that you intend for this entity to track that does not apply to an Employee.
Do I store the userId in the employee entity
I would model Employee and User separately. An Employee can be 1:0-1 linked to a User, ideally with a UserId assigned to an Employee (Employee has a UserId). If you did this the other way around then you would end up with many fields in your User entity such as SupervisorId and potentially ClientId. You can make it work, but it is not scalable to keep adding fields to the User entity as you evolve your solution.
This will also allow you to model the data for a past or future employee without having to grant them access to the system, it will also allow you to evolve the User requirements without affecting your business logic that is centred around your Employee implementation.
- You should also consider the future growth opportunity of a client being able to login as their own
User to view reports or otherwise access or provide information.
is the employees ID just the same as the userId
If Employee inherits from User (1:1) then you cannot have an Employee that is not also a User it will also become hard to associate multiple identities to your employee when that becomes important, or if you do then you will end up adding another entity to model Identity instead of your User entity.
It is up to you to decide which of these trade-offs you want for your model. 1:1 between User and Employee can certainly be made to work, there are many ways to do this, DDD does not specifically constrain us in either way. Take the time to understand the implications of your design decisions and evaluate them against the alternatives.