0

I'm trying to manually log in a user within a Controller or a Route. This works during the scope of the page, but it doesn't persists.

Here is my code :

Route::get('check', function (){
    if (Auth::loginUsingId(1)) { // User #1 is existing in the DB
      return redirect()->intended('/check2');
    }
});

Route::get('check2', function (){
    dd(Auth::user());
});

And I got : null on my /check2 page

Can someone give me a quick hint?

PS: I tested the default Auth Laravel system and it works.

Thank you very much!

  • I don't notice anything immediate, but I feel like it's got to be something very simple. Does it set cookies? Does it create the session on the back end? – Captain Hypertext Feb 23 '16 at 23:50
  • Same thing? https://stackoverflow.com/questions/21603347/laravel-authattempt-will-not-persist-login?rq=1 – Chris Feb 24 '16 at 00:54
  • what version of 5, there are technically 3 different versions, each with their own subversions. – lagbox Feb 24 '16 at 02:10

1 Answers1

1

The issue was simple. On Laravel 5.2, you need to wrap all concerned Routes inside the middleware "web" in order to play with Authentification.

Thanks all.