It's better to assign 1 subdomain for each application you have instead of combining multiple subdomains on one app.
Session only for specific (sub)domains
I'm having multiple applications on the same domain, but some have additional subdomains. Would the following be possible?
session.php of the first application:
'domain' => [
'website.com',
'app1.website.com',
'app2.website.com'
];
session.php of the second application:
'domain' => [
'app3.website.com'
];
I know it's possible to use '.website.com' but this overwrites the other subdomain cookies.
It is hardcoded in the SessionGuard class:
https://github.com/laravel/framework/blob/7.x/src/Illuminate/Auth/SessionGuard.php#L728-L736
The $this->name used to generate the string is the guard name, that is the web in your cookie names.
But does it work without the remember feature?
If so, a quick fix would be renaming the web guard for each app in each app's ./config/auth.php
You would change the 'web' key on the 'guards' element to something else, for example: 'appA' and change the 'guard' key inside the 'defauit' element to the same key, for example:
'defaults' => [
'guard' => 'appA', // change here
'passwords' => 'users',
],
'guards' => [
'appA' => [ // change here
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
],
The downside of doing this is if you are using multiple guards in your app you will have to change every instance of web to appA, for example when using the auth middleware:
// $this->middleware('auth:web');
$this->middleware('auth:appA');
Another thing you can try is extending the SessionGuard to override its getRecallerName method to use a configurable name. See the docs for using a custom guard:
https://laravel.com/docs/6.x/authentication#adding-custom-guards
And finally one other option is to send a PR to the core to allow customizing this cookie name from a config file.
Please or to participate in this conversation.
