User Auth not persisting within Laravel package

前端 未结 2 1629
醉话见心
醉话见心 2021-02-20 14:28

This is my first attempt at a laravel package and have run into an issue where Auth::attempt($credentials) works within my login controller, but upon redirection to a protected

相关标签:
2条回答
  • 2021-02-20 14:41

    Turns out the issue was with the new web middleware, moved all my routes that require session data in to the route group and everything works as normal.

    Route::group(['middleware' => ['web']], function () {
    
        Route::get("/login", ['uses'=>'SiteLogin@index']);
        Route::post("/login", ['uses'=>'SiteLogin@attempt']);
        Route::get("/logout", ['uses'=>'SiteLogin@logout']);
    
        Route::group(['prefix' => 'admin', 'middleware' => 'auth'], function () {
            Route::get('/', ['uses'=>'Admin@index']);
        });
    });
    
    0 讨论(0)
  • 2021-02-20 14:49

    The default behavior of the method attempt is to not keep the user logged.

    You should change it to:

    if (Auth::attempt(array('email' => $email, 'password' => $password), false, true))
    

    This way you will set remember as false and login as true.

    Check more about this here: https://laravel.com/docs/5.2/authentication

    0 讨论(0)
提交回复
热议问题