Skip to content

Commit

Permalink
fix: Fix issue with cookie path
Browse files Browse the repository at this point in the history
  • Loading branch information
ollieread committed Nov 18, 2024
1 parent 055a01b commit 44342e6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 44 deletions.
27 changes: 6 additions & 21 deletions src/Concerns/OverridesCookieSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,9 @@
trait OverridesCookieSettings
{
/**
* @var string|null
* @var array{path?:string|null,domain?:string|null,secure?:bool|null,same_site?:string|null}
*/
protected static ?string $path = null;

/**
* @var string|null
*/
protected static ?string $domain = null;

/**
* @var bool|null
*/
protected static ?bool $secure = null;

/**
* @var string|null
*/
protected static ?string $sameSite = null;
protected static array $settings = [];

/**
* Set the cookie domain
Expand All @@ -42,7 +27,7 @@ trait OverridesCookieSettings
*/
public static function setDomain(?string $domain): void
{
self::$domain = $domain;
self::$settings['domain'] = $domain;
}

/**
Expand All @@ -54,7 +39,7 @@ public static function setDomain(?string $domain): void
*/
public static function setPath(?string $path): void
{
self::$path = $path;
self::$settings['path'] = '/' . ltrim($path, '/');
}

// @codeCoverageIgnoreStart
Expand All @@ -68,7 +53,7 @@ public static function setPath(?string $path): void
*/
public static function setSameSite(?string $sameSite): void
{
self::$sameSite = $sameSite;
self::$settings['same_site'] = $sameSite;
}

/**
Expand All @@ -80,7 +65,7 @@ public static function setSameSite(?string $sameSite): void
*/
public static function setSecure(?bool $secure): void
{
self::$secure = $secure;
self::$settings['secure'] = $secure;
}
// @codeCoverageIgnoreEnd
}
8 changes: 4 additions & 4 deletions src/Overrides/CookieOverride.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public static function service(): string
public function setup(Tenancy $tenancy, Tenant $tenant): void
{
// Collect the values
$path = self::$path ?? config('session.path') ?? '/';
$domain = self::$domain ?? config('session.domain');
$secure = self::$secure ?? config('session.secure', false);
$sameSite = self::$sameSite ?? config('session.same_site');
$path = self::$settings['path'] ?? config('session.path') ?? '/';
$domain = self::$settings['domain'] ?? config('session.domain');
$secure = self::$settings['secure'] ?? config('session.secure', false);
$sameSite = self::$settings['same_site'] ?? config('session.same_site');

/**
* This is here to make PHPStan quiet down
Expand Down
24 changes: 5 additions & 19 deletions src/Overrides/SessionOverride.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,29 +99,15 @@ public function boot(Application $app, Sprout $sprout): void
*/
public function setup(Tenancy $tenancy, Tenant $tenant): void
{
// Collect the values
$path = self::$path ?? config('session.path') ?? '/';
$domain = self::$domain ?? config('session.domain');
$secure = self::$secure ?? config('session.secure', false);
$sameSite = self::$sameSite ?? config('session.same_site');

/**
* This is here to make PHPStan quiet down
*
* @var string $path
* @var string|null $domain
* @var bool|null $secure
* @var string|null $sameSite
*/
$settings = self::$settings;

/** @var \Illuminate\Contracts\Config\Repository $config */
$config = config();

// Set the config values
$config->set('session.path', $path);
$config->set('session.domain', $domain);
$config->set('session.secure', $secure);
$config->set('session.same_site', $sameSite);
foreach ($settings as $setting => $value) {
$config->set('session.' . $setting, $value);
}

$config->set('session.cookie', $this->getCookieName($tenancy, $tenant));

// Reset all the drivers
Expand Down

0 comments on commit 44342e6

Please sign in to comment.