简体   繁体   English

会话未启动Laravel 5.3 Auth

[英]Session is not started Laravel 5.3 Auth

I am trying to authenticate user against an API in Laravel 5.3. 我正在尝试根据Laravel 5.3中的API对用户进行身份验证。 It is not working. 它不起作用。 Auth does not persist once the user redirects after login. 用户在登录后重定向后,Auth不会保留。


Routes are configured like: 路由配置如下:

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'm using 在LoginController.php我正在使用

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

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

After login which is successfully saved in file, the session is not started for route '/' . 登录成功保存在文件中后,路由'/'的会话不会启动。

So on 'login' route: 所以在'login'路线:

dd($session); in Illuminate\\Auth\\SessionGuard returns #started : true 在Illuminate \\ Auth \\ SessionGuard中返回#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 #started is false when the route is in 'auth' middleware group ( '/' in my case). 但是当路由在'auth'中间件组(在我的情况下是'/' )时, #started是错误的。

I checked some and #started is also false when I put the '/' route outside 'auth' middleware group but calling Auth::check() in controller. 我检查了一些,当我将'/'路由放在'auth'中间件组之外但在控制器中调用Auth::check()时, #started也是假的。

This problem seems to have existed in 5.2 ( Auth not persisting in Laravel 5.2 ), but the solution there not working for me. 这个问题似乎已经存在于5.2中( Auth不会在Laravel 5.2中持续存在 ),但那里的解决方案并不适用于我。

Please help me understand why I can't access the '/' route after logging in. Thank you! 请帮助我理解登录后无法访问'/'路由的原因。谢谢!

change kernel.php 'api' 改变kernel.php'api'

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

to

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM