Auth::user() doesn't travel across subdomains? - Laravel 5.2

隐身守侯 提交于 2019-12-03 07:47:39

In config/session.php you should change:

'domain' => null,

into

'domain' => '.example.ca',

You should also clear all the cookies

Thanawat Tohard

In config/session.php you should change:

'domain' => null,

into

'domain' => '.example.ca',

and for main domain

'files' => storage_path('framework/sessions'), 

For subdomain I point to path of main domain ??/framework/sessions'.

After that, I can use Auth

just want to add to the answer

other than setting domain to '.domain.com' in config/session, also make sure that both main domain and subdomain are accessing the same users table and the same sessions table

laravel stores the user ID in the session, so if you have different table, that ID won't be found in the subdomain, thus not logged in and cannot access Auth::

For anyone getting the same error, I followed all above until I did these:

  1. Choose either database or redis as your session driver. I chose redis and I input that into my env and and even into the default of config.session.driver, for good measure.

  2. I changed the domain name to '.domain.com' as all have suggested above.

  3. However, having done all that, strangely, there was no change, until I changed the session cookie name. By default it has: 'APP_NAME', 'Laravel'), '_').'_session' I only changed the 'Laravel' part to my domain...

  4. Lastly, clearing the cookie from the conventional way didn't work. At least for me using firefox. I had to open up the dev tools and delete all the sites entry under Storage > Cookies And like magic, boom! It worked! Try it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!