lundi 25 avril 2016

No logged in user in Authenticate middleware but in other Middlewares

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



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire