1

I am using Laravel 5.8 and I want to build multiple guards login system using single sign in page for all guards, so, I overwritten the attemptLogin function in LoginController as follow:


public function attemptLogin(Request $request){
 if(Auth::guard('marketer')->attempt($request->only('email','password'),$request->filled('remember'))){
            //Authentication passed...
//            dd();
            return redirect()
                ->intended(url('/home'))
                ->with('status','You are Logged in as marketer!');
        }
        if(Auth::guard('admin')->attempt($request->only('email','password'),$request->filled('remember'))){
            //Authentication passed...
//            dd(session()->all());
            return redirect()
                ->intended(url('/home'))
                ->with('status','You are Logged in as admin!');
        }
return $this->loginFailed();
}

and I set up admin in admins table, when trying to login using the correct email and password and when I uncomment dd(session()->all()); I see Laravel is generating session, but, once I comment dd(session()->all()); and try Auth::check() I get false.

it seems either Laravel is not persisting the session or it is regenerating it in such way Auth::check return false.

what is the problem? how to fix it?

3
  • @ArunAS the command you gived is returning true, but, when route is protected by auth middleware then should not the admin be able to view that route? take for example /home Commented May 23, 2020 at 22:06
  • I didn't quite understand what you meant, but do ensure that you specify all guard names on the /home route. Check this Commented May 23, 2020 at 22:16
  • @ArunAS that is the answer I am looking for, if you like please write your answer so I accept it Commented May 23, 2020 at 22:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.