Home > OS >  Laravel Auth redirects to Login after authentication
Laravel Auth redirects to Login after authentication

Time:08-31

I recently changed the Auth default table from users to employees now the problem i have is it keeps redirecting to login form after authentication. the Auth::attempt method returns true but it keeps redirecting to login page.

defaults' => [
    'guard' => 'web',
    'passwords' => 'users',
],


'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],
    'employees' => [
        'driver' => 'session',
        'redirectTo' => 'employee.dashboard',
        'provider' => 'employees',
    ],
],


],


'passwords' => [
    'users' => [
        'provider' => 'users',
        'table' => 'password_resets',
        'expire' => 60,
        'throttle' => 60,
    ],
    'employees' => [
        'provider' => 'employees',
        'table' => 'password_resets',
        'expire' => 60,
        'throttle' => 60,
    ],
],


'password_timeout' => 10800,

CodePudding user response:

in loginController file

class LoginController extends Controller
{
    protected $redirectTo = '/panel';
    protected function redirectTo()
     {
        if (auth()->user()->role == 'admin') {
            return '/admin';
        }
        return '/home';
     }

}

you can use redirectTo property or method. the method overrides the property

CodePudding user response:

Solved it, forgot to change the default guard to employees. Also you have to pass the primary key in your model so that the session persist.

  • Related