Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

janaki_patel's avatar

Multi Authentication in laravel 10

I want to implement multi authentiation system in laravel 10, for both customer user as well admin can access site in same browser at a time in different window .

I have implemented multi auth using guard with two different tables 'admins' and 'users' but , still facing issue. not able to persist both user login together. Let's I am make login with Customer user and next when i am perform login with admin at that time customer user will be logout.

Code for config/auth.php file


  'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],
'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
        'admin' => [
            'driver' => 'session',
            'provider' => 'admins',
        ],
    ],
 'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => env('AUTH_MODEL', User::class),
        ],
        'admins' => [
            'driver' => 'eloquent',
            'model' => env('AUTH_MODEL', Admin::class),
        ],      
    ],

Please look it and let me know solution if you found any issue.

Thanks for Advance !!

0 likes
2 replies
Snapey's avatar

scrap that idea. Your user gets a session cookie, and there can only be one. Its not possible to log in twice.

And how confusing would it be for admins to have two sets of usernames and passwords.

Besides, we post here almost daily not to use multiple guards as they are an unnecessary complication

1 like
ahmedmansour08's avatar

@janaki_patel There is Many ways to implement multi auth @ Laravel Application

Your Code Is Great But Some Changes :) .

Using ADMIN_AUTH_MODEL instead of AUTH_MODEL @ Admin Guard

   'defaults' => [
         'guard' => 'web',
         'passwords' => 'users',
     ],
 'guards' => [
         'web' => [
             'driver' => 'session',
             'provider' => 'users',
         ],
         'admin' => [
             'driver' => 'session',
             'provider' => 'admins', 
         ],
     ],
  'providers' => [
         'users' => [
             'driver' => 'eloquent',
             'model' => env('AUTH_MODEL', User::class),
          ],
         'admins' => [
             'driver' => 'eloquent',
             'model' => env('ADMIN_AUTH_MODEL', Admin::class),
         ],      
     ],	

@ App\Http\Kernel.php

You Can Add middlewareGroups @ $middlewareGroups

Example :

	 'admin'    => [
            \App\Http\Middleware\AdminMiddleware::class,
		    // other Middleware ......
        ],
        'company'  => [
            \App\Http\Middleware\UserMiddleware::class,
		    // other Middleware .....
        ],					

The Below Section Will Be important if you Using a Shared Functions ( Traits , Actions , ..... )

  • AdminMiddleware will contain : Auth::shouldUse('admin');
  • UserMiddleware will contain : Auth::shouldUse('user');

Please or to participate in this conversation.