Auth :: user () not navigating subdomains? - Laravel 5.2

I have a subdomain on my site, for example:

http://example.ca http://blog.example.ca 

Only people who have a URL, that is, its public or well-known knowledge, are accessible on the blog. I have a bunch of routes associated with this domain that requires you to log in.

I said in nav.blade.php that if the user is logged in, there should be a drop-down list, and if not, then there should not be a drop-down list.

everything works for http://blog.example.ca , but when I go to http://example.ca I am no longer authenticated.

Is there any way in the bot to make me authenticated in all subdomains? Not only those who have controller actions that require authentication?

+6
source share
4 answers

In config/session.php you should change:

 'domain' => null, 

in

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

You must also clear all cookies.

+15
source

For those who got the same error, I followed all the above until I did this:

  1. Select the database or redis as the session driver. I selected redis and enter this in my env and even in the default config.session.driver file, for a good measure.

  2. I changed the domain name to ".domain.com", as everyone suggested above.

  3. However, having done all this, oddly enough, no changes happened until I changed the name of the session cookie. By default it has: 'APP_NAME', 'Laravel'), '_') .'_ session 'I just changed the part of' Laravel 'to my domain ...

  4. Finally, clearing cookies from the usual method did not work. At least for me using Firefox. I had to open the developer tools and delete all the site records in the "Storage"> "Cookies" section. And as if by magic, boom! It worked! Try.

0
source

In config/session.php you should change:

 'domain' => null, 

in

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

and for the main domain

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

For the subdomain, I specify the path to the main domain ??/framework/sessions' .

After that I can use Auth

-1
source

just want to add to the answer

in addition to setting the domain on .domain.com in config / session, also make sure that both the main domain and the subdomain get access to the same user table and the same session table

laravel stores the user ID in the session, so if you have another table, this identifier will not be found in the subdomain, so it will not log in and will not be able to access Auth ::

-1
source

Source: https://habr.com/ru/post/1239328/


All Articles