samedi 23 mai 2020

laravel auth::attempt not saving session

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?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire