I've got questions and problems: First here is my code:
AuthMiddleware.php
public function handle($request, Closure $next)
{
if (auth()->check()) {
return $next($request);
} else {
if (auth()->viaRemember()) {
return $next($request);
}
}
return redirect()->route('auth.index');
}
AuthController.php
if (auth()->attempt(compact('email', 'password'), true)) {
return redirect()->route('dashboard');
}
Kernel.php
protected $routeMiddleware = [
'auth.check' => \App\Http\Middleware\AuthMiddleware::class,
]
routes.php
Route::group(['prefix' => 'auth'], function () {
Route::get('/', 'AuthController@index')->name('auth.index');
Route::post('login', 'AuthController@login');
});
Route::group(['middleware' => 'auth.check'], function () {
Route::get('dashboard', function () {
return view('front.welcome');
})->name('dashboard');
});
Here is the problem:
Every time I close my browser (with
expire_on_close:true
on session file) the page will redirect me to/login
instead of/auth
. I can't find the code why it redirect me to/login
. Any solution?I want to apply rememberMe function. But every time I close my browser it always log me out. I've tried set
expire_on_close:false
. Yes, it's working but everytime I runauth()->viaRemember()
it always return me false. Any suggestion?
My Session using file.