user3534846
user3534846

Reputation: 21

Laravel 5.5 Session getting lost on each request

When logging in, authentication works and the user is redirected to the logged-in page (/home at first but I also tried changing to /dashboard) but then the session seems to become lost as it shows an empty array when logging on the logged-in controller.

My setup involves using Redis as a session store but I have tried file and database drives as well with the same results.

Even stranger, I am able to view the session data in my redis cli without any issues.

Some "fixes" I have tried to no avail are:
- removing underscores from session cookie name (as well as dashes/hyphens)
- changing session domain setting to all combinations of main domain and subdomain

Does anyone have any ideas on any other possible fixes?

UPDATE:

Other fixes tried:

Upvotes: 2

Views: 1314

Answers (2)

Fawaz Al Romy
Fawaz Al Romy

Reputation: 64

The problem resolved with me after remove \App\Http\Middleware\EncryptCookies::class from web inside $middlewareGroups in app\Http\Kernel.php file.

Upvotes: 0

tintinboss
tintinboss

Reputation: 672

Where did you write your Routes ? Please note that the web middleware uses the default Laravel Session.

So routes written in routes/web.php are the ones using Laravel Session. You can also try using the file driver, but make sure the /storage folder has at 0755 permission.

also, can you please check you App\Providers\RouteServiceProviders mapWebRoutes() method looks like this?

/**
 * Define the "web" routes for the application.
 *
 * These routes all receive session state, CSRF protection, etc.
 *
 * @return void
 */
protected function mapWebRoutes()
{
    Route::middleware('web')
         ->namespace($this->namespace)
         ->group(base_path('routes/web.php'));
}

Assuming you didn't modify the app\Http\Kernel.php

Upvotes: 1

Related Questions