Skip to content

Commit

Permalink
fix: pass host in right way to cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
obarbosa89 committed Dec 29, 2024
1 parent 66a160b commit 3bcfcdd
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ public function run(): void

$this->setRouter();

$uri = Uri::new(Config::get('app.url'));
$port = (int) Config::get('app.port');

$this->server->expose(new Socket\InternetAddress($uri->getHost(), $port));
$this->server->expose(new Socket\InternetAddress($this->getHost(), $port));

$this->server->start($this->router, $this->errorHandler);

Expand Down Expand Up @@ -146,9 +145,10 @@ private function setRouter(): void
$globalMiddlewares = array_map(fn (string $middleware) => new $middleware(), $middlewares['global']);

$cookieAttributes = CookieAttributes::default()
->withDomain($this->getAppDomain())
->withDomain($this->getHost())
->withExpiry(Date::now()->addMinutes(30)->toDateTime())
->withSameSite(CookieAttributes::SAMESITE_LAX);
->withSameSite(CookieAttributes::SAMESITE_LAX)
->withHttpOnly();

// app.ssl or app.secure or app_server_cert
if (Config::get('session.secure', false)) {
Expand All @@ -162,9 +162,10 @@ private function setRouter(): void
$this->router = Middleware\stackMiddleware($router, ...$globalMiddlewares);
}

private function getAppDomain(): string
private function getHost(): string
{
// Scheme: http or https
return Config::get('app.url') . ':' . Config::get('app.port');
$uri = Uri::new(Config::get('app.url'));

return $uri->getHost();
}
}

0 comments on commit 3bcfcdd

Please sign in to comment.