簡體   English   中英

會話未啟動Laravel 5.3 Auth

[英]Session is not started Laravel 5.3 Auth

我正在嘗試根據Laravel 5.3中的API對用戶進行身份驗證。 它不起作用。 用戶在登錄后重定向后,Auth不會保留。


路由配置如下:

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');

});

在LoginController.php我正在使用

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

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

登錄成功保存在文件中后,路由'/'的會話不會啟動。

所以在'login'路線:

dd($session); 在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

}

但是當路由在'auth'中間件組(在我的情況下是'/' )時, #started是錯誤的。

我檢查了一些,當我將'/'路由放在'auth'中間件組之外但在控制器中調用Auth::check()時, #started也是假的。

這個問題似乎已經存在於5.2中( Auth不會在Laravel 5.2中持續存在 ),但那里的解決方案並不適用於我。

請幫助我理解登錄后無法訪問'/'路由的原因。謝謝!

改變kernel.php'api'

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

'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