Have you added the middleware group 'web' to your routes. In 5.1 , this was default for all the routes and was used for session management and csrf verification etc.
Auth session killed after redirect | laravel 5.2
We made a simple login form, when we post it its working fine, we are even logged in if we check the authentication inside the Auth::attempt(). But when we redirect to the dashboard the session is empty and we are not authenticated. Why is this happening? We are using the new laravel 5.2. Here a link to our controller: http://laravel.io/bin/nQm3W Link to route: http://laravel.io/bin/Jx7J7 Link to dashboard controller: http://laravel.io/bin/QNEVx
Sorry, if this is confusing, your AuthController must use the middleware routes where it creates a session for you. As of now, only your DashboardController does that , which is the reason by authenticated session does not persist.
Route::group(['middleware' =>[ 'web']], function () {
Route::get('/login', ['as' => 'login', 'uses' => 'Auth\AuthController@getLogin']);
Route::post('/login', ['as' => 'login', 'uses' => 'Auth\AuthController@postLogin']);
});
Route::group(['middleware' => ['web','auth'], function () {
Route::get('/dashboard', ['as' => 'dashboard', 'uses' => 'DashboardController@getIndex']);
}
and refactor your middleware group as
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
],
'auth' => [
\App\Http\Middleware\Authenticate::class,
... whatever else you need
],
Please or to participate in this conversation.