I have a Laravel 5.2 app where I'm trying to login a user in an Event Listener. All routes are wrapped in web middleware, I'm using database for the session and I see it creates an entry when the event listener executes, however accessing other pages later behave as if there's no user in session.
Just to test out my code, I added the same listener code in a controller route and that works, it persists. I'm suspecting this has to do with the web middleware not being available to an event listener.
What do I have to do to get the event listener login to persist across the app ?
// EventListener, doesn't persist
public function handle(Saml2LoginEvent $event)
{
$user = $event->getSaml2User();
$laravelUser = User::where('mail', $user->getAttributes()['mail'][0])->where('active', 1)->first() ;
Auth::guard('web')->login($laravelUser);
}
// UserController, persists !
public function home(Request $request){
$laravelUser = User::where('mail', 'test@mail.com')->where('active', 1)->first() ;
Auth::guard('web')->login($laravelUser);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire