Introduction
My problem is, that I have no logged in user when trying to use the auth
middleware to restrict a route to logged in users but I do have one when getting redirected back to the login page.
Details
Let's just assume I have only these two routes
Route with web middleware
$router->group(['middleware' => 'web'], function($router) {
/** @var Registrar $router */
$router->get('/', ['as' => 'home', 'uses' => 'HomeController@index']);
});
Route with auth middleware
$router->group(['middleware' => 'auth'], function($router) {
$router->get('/listings', ['as' => 'listings', 'uses' => 'ListingController@index']);
});
The first route works without problems, the second route however redirects me back to the login page. This should only be done, when I have no logged in user, but I logged in before! Which is weird.
When I add these two lines of code to the handle
function of the Middleware
Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse
which is used in the web
group
$user = \Auth::user();
dd($user);
I'm getting a dump of a the currently logged in user object. However, when adding those lines in the FeedParser\Http\Middleware\Authenticate
Middleware I'm getting null
as a dump. How can it be, that the user is logged in in the one middleware, but not in the other? What do I need to do to make it work again? Or better: What more information would you need to help me solve the problems
Updates
If someone asks for more information or more code I will post it here
答案 0 :(得分:1)
I imagine this happened after upgrading to 5.2?
I believe the route should include both the web
and the auth
middleware, such as:
Route::group(['middleware' => ['web', 'auth']], function() {
Route::get('home', 'HomeController@dashboard')->name('home');
});