diff --git a/src/Application/User/Service/Authentication.php b/src/Application/User/Service/Authentication.php index f9159033..cc8cef18 100644 --- a/src/Application/User/Service/Authentication.php +++ b/src/Application/User/Service/Authentication.php @@ -49,14 +49,17 @@ public function login(string $password, bool $rememberMe) : void throw InvalidPassword::create(); } - $expirationDate = $this->createExpirationDate(); + $authTokenExpirationDate = $this->createExpirationDate(); + $cookieExpiration = 0; + if ($rememberMe === true) { - $expirationDate = $this->createExpirationDate(self::MAX_EXPIRATION_AGE_IN_DAYS); + $authTokenExpirationDate = $this->createExpirationDate(self::MAX_EXPIRATION_AGE_IN_DAYS); + $cookieExpiration = (int)$authTokenExpirationDate->format('U'); } - $token = $this->generateToken(DateTime::createFromString((string)$expirationDate)); + $token = $this->generateToken(DateTime::createFromString((string)$authTokenExpirationDate)); - setcookie(self::AUTHENTICATION_COOKIE_NAME, $token, (int)$expirationDate->format('U')); + setcookie(self::AUTHENTICATION_COOKIE_NAME, $token, $cookieExpiration); } public function logout() : void