Persisting Sessions across Subdomains
I have already tried to change session config :
'domain' => '.example.com'
But whenever i make this change.. Auth::check() stops working or i get TokenMismatchException if i try to login through private window..
I also tried deleting browser cache & cookies but i am still stuck on TokenMIsmatch after doing that.
Any help would be appreciated.
@bytefury have you tried to prefix it with a *?
'domain' => '*.example.com'
Also, you may want change your session driver to something like memcached or redis (preferred) on another server.
@bytefuy the only thing that worked for me is setting the driver to database.
Also i would like to mention that i am currently testing this locally on 'shop.app' . Does it have anything to with that?
Sessions are working fine after hardcoded the domain name' :
'domain' => '.shop.app'
Is this the correct way to go?
Okay figured out this headache!! Note, I am using Homestead.
So, you have to do a few things:
- Update the url configuration in
config/app.php from http://localhost to the actual URL you are using, http://domain.com
- Update the domain configuration in
config/session.php to .domain.com (make sure you insert the "." prefix)
If using Homestead, I highly recommend using Redis for the session handler since it basically comes out of the box. To do so:
- composer require predis/predis
- Update SESSION_DRIVER to equal redis in
.env
- Update connection configuration in
config/session.php to default
Please or to participate in this conversation.