1

Every time I reload the page, I get a new value out of session()->getId().

Some have suggested adding the laravel_session to the unencrypted cookie exception, but this does not fix it and is not a viable option anyway.

The issue persists no matter which session storage method I use. File, redis, etc all have the same problem.

This is happening on a fresh install of Laravel 7.

Contents of .env:

SESSION_DRIVER=redis
SESSION_LIFETIME=1440
SESSION_DOMAIN=example.test

What's causing this?

eComEvo
  • 11,669
  • 26
  • 89
  • 145
  • CHECK inside Kernel.php and make sure you dont have duplicate classes like StartSession, AuthenticateSession, Specially inside middleware groups array – Bira Jun 05 '20 at 09:09

1 Answers1

1

That means:

  1. Session driver is not starting up properly
  2. Client you're using to connect to laravel app server does not accept cookies
  3. Cookies are set up for wrong domain and/or path.

For case 1 make sure StartSession middleware exists in app/Kernel.php at $middlewareGroups -> web

For case 3 check this answer. In case your app relies on a single domain/path, I recommend you to remove SESSION_DOMAIN.


Finally, manually remove all sessions from your session driver, then run php artisan config:cache and try again.

user8555937
  • 2,161
  • 1
  • 14
  • 39
  • 1
    The issue was that I didn't put my middleware that reads the session in the `web` section but instead put it in the general middleware array where `StartSession` middleware was not defined. – eComEvo Jun 06 '20 at 05:35