Session not running Laravel 5.3 Auth

I am trying to authenticate a user against an API in Laravel 5.3. This does not work. Auth is not saved after redirecting a user after logging in.


Routes are configured as follows:

Route::group(['middleware' => 'web'], function () {
    Route::group(['middleware' => 'auth'], function () {
        Route::get('/', 'Users\DashboardController@index');
    });
    // Authentication routes...
    Route::get('login', 'Auth\LoginController@getLogin');
    Route::post('login', 'Auth\LoginController@postLogin');
    Route::get('logout', 'Auth\LoginController@getLogout');

});

In LoginController.php I use

protected $redirectTo = '/';
public function getLogin()
{
    return view('auth.login');
}

public function postLogin(Request $request)
{
    $this->login($request);
}

After logging in to a system that was successfully saved to a file, the session does not start for the route '/'.

So the route 'login':

dd($session); in Illuminate \ Auth \ SessionGuard returns #started : true

Store {#153 ▼
 #id: "fo9Q8WuBio5BBus70WmzFPZmkXkjsYQlYEHsVHI4"
 #name: "laravel_session"
 #attributes: array:4 [▼]
 #bags: []
 #metaBag: MetadataBag {#144 ▼}
 #bagData: array:1 [▼]
 #handler: FileSessionHandler {#154 ▼}
 #started: true

}

but #startedis false when the route is in 'auth'the middleware group ( '/'in my case).

I checked some, and #startedalso incorrectly, when I placed the route '/'outside the middleware group 'auth', but called Auth::check()in the controller.

, , 5.2 (Auth, Laravel 5.2 ), .

, , '/' . !

+4
1

kernel.php 'api'

api' => [
            'throttle:60,1',
            'bindings',
        ],

'api' => [
            'throttle:60,1',
            'bindings',
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Session\Middleware\StartSession::class,
        ],
+1

Source: https://habr.com/ru/post/1658262/


All Articles