Authentication and Authorization using Two (Multiple) Tables

Hello

In my project I need to have two separate tables for “company_users” and “public_users” the Authentication on one would be with usernames and the other one with email addresses. They also contain their own set of roles and Authorization requirements.

In older versions of CakePHP this was possible using the Auth Component but I can’t find a decent way to do this using the current Authentication Plugin in CakePHP 5.
I was wondering if there is a clean way to implement the Authentication and Authorization for these two tables?

Thank you.

$user = $this->getTableLocator()->get('Users')->get(intval($userId),[
                   'contain' => [
                       'Parents' => [
                           'queryBuilder' => function($query){
                               return $query->find('all',['withDeleted']);
                           }
                       ],
                       'Students' => [
                           'queryBuilder' => function($query){
                               return $query->find('all',['withDeleted']);
                           }
                       ]
                   ]
               ]);
               $this->Authentication->setIdentity($user);

try this one

Migration from the AuthComponent - 2.x (cakephp.org)

Nothing about your suggested code has anything to do with authorizing against multiple tables.

yes the code you suggested is not working i tried it

Check out the new auth plugin - pretty sure you can use Username or email for login

Why not add a flag in the user table for company employee?