vincent15000's avatar

Multiple authenticatable / notifiable models or one users table with many roles ?

Hello,

I have a first version of an app with many types of people :

  • admin, user, ... can connect to the app

  • trainers, students cannot connect to the app and are for the moment in trainers / students tables, that's interesting because according to the roles (trainer, student, admin, ...) I don't have the same informations to save in the database

In a new version of the app, I need to let the trainers / students connect to the app. What are the best solutions ?

  • is it possible to set the trainers / students tables authenticable and notifiable like the users table ? but I think that it will not be pratice to handle

  • is it better to migrate all people to the users table and assign roles to each type of users (admin, user, trainer, student, ...) ? I think it will probably be the easiest way

Perhaps there is many more solutions I don't think about ?

What would you suggest me ?

Thanks for your help.

Vincent

0 likes
18 replies
MohamedTammam's avatar
Level 51

Don't use multiple tables for users, Users are users no matter how many roles they have.

You can create another table for data that's only for student or only for trainers for example, and use only one table for users.

And also I don't recommend using multiple models for users. You will have redundant work, unless you know what you're doing 100%.

1 like
vincent15000's avatar

@MohamedTammam Ok so for you the best way would be to migrate all people to one table and handle the authentication in one table and then reorganize the database with this constraint.

jlrdw's avatar

@vincent15000 each system is different and has certain specifications. For example a large Hospital chain is going to have Separate Tables for patients and the physician portal.

Humana military has user, physician, and government separate logins and tables.

And some government agencies you have to code to a spec they will tell you whether to use the same table or Separate Tables.

1 like
vincent15000's avatar

@jlrdw So you suggest to use multiple tables for big applications and use only one table for little applications ? That's interesting.

MohamedTammam's avatar

@vincent15000 I wouldn't follow that article.

Imagine you want to have a profile picture for users, now you need to do it for each table and model. Imagine about payments, settings, etc. Users are users with different roles.

1 like
Sinnbeck's avatar

@vincent15000 I have tried maintaining a thing like this once. Each part had a seperate login and table. Then we started having users with multiple logins. It was a constant struggle as they changed their password in one system and assumed it worked in all. But as each login was it's own silo, that didn't work

1 like
vincent15000's avatar

@Sinnbeck Oh yes I didn't thought about such a case with a user having an account in the different tables.

Sinnbeck's avatar

@vincent15000 we ended up merging it all into one table. Took almost a complete week for 2 people. Time could have been saved if it had been made like that from day one

We made 1 login page and if more than 1 "role" is detected we would show a "select product" screen

1 like
vincent15000's avatar

@Sinnbeck A select product screen ? You mean a screen to select with which role the user wants to connect ?

Sinnbeck's avatar

@vincent15000 kinda yeah. Except we sold multiple products, each with their own routes and tables. So select product :) but it could just as well have been roles or jobs

1 like
jlrdw's avatar

@vincent15000 I didn't really suggest one way or the other I just said go by a specification if you have one.

An example is the Texas Department of Aging and Disability Services has separate Tables for supervisors versus employee.

Yes the supervisor is an employee but he or she logs out and having to log back in if going into a regular employee function such as a training session that all employees go through.

1 like
vincent15000's avatar

@jlrdw Ok thank you. Yes it was only an example and it depends on the specifications, I had understood it that way.

Please or to participate in this conversation.