davides98's avatar

Multi auth Laravel 8

I would like to create a multi-auth app. I would like to manage everything with two different tables. Admin table User table I would also like to access two different login pages admin-> login_admin users-> login_users The concept is similar to an ecommerce ... Do you have any advice on how to do it?

0 likes
6 replies
martinbean's avatar

I would like to manage everything with two different tables.

@davides98 Why? A user is a user. Why have two tables with pretty much the same information (name, email, password)?

Just use roles, and then authorisation to determine what that user can do based on their role(s). Otherwise what happens when you need to make a third user type, such as warehouse worker? Are you just going to create a third auth guard, third bunch of controllers, views, etc? No. That’s wholly inefficient.

davides98's avatar

My idea was to separate users and admins for security, then set the roles and permissions in the admins table. ex. admins table -> role 1 = superadmin -> role 2 = editor -> role 3 writer

eludic's avatar

I use a similar concept for an application developed in Laravel 7. I use a couple of packages with some custom coding.

a) I use custom Guard to log them according to the user type (staff and user in my case)

b) Depending upon the type roles are assigned to use using Spatie's Laravel Permission package (https://spatie.be/docs/laravel-permission/v3/introduction)

c) I use Laravel modules (https://nwidart.com/laravel-modules/v6/introduction) for various modules in my application where I have different controllers for my backend and frontend

Hope this helps.

1 like
eludic's avatar

That is exactly what I did, created guards and controllers for them. For the staff I use the default Laravel guard which uses the User table.

jlrdw's avatar

Authentication for login and use authorization to determine want the logged user can and cannot do.

Please or to participate in this conversation.