The cookie not saved after server respond with {"status": "ok"}
Opened this issue · 4 comments
szotyi41 commented
Maybe I found an issue. I used this package in our older project and everything worked.
In our new project, the popup came back constantly and when I checked the cookie is saved at the Application tab, it is not.
I started to find differences, and I found the domain was different.
It is saved to .env in the same way, but older project (mvs) has no domain parameter in Set-Cookie.
But the newer project it has with https://.
Now I hacked the configuration file like this and it is working.
'url' => [
'domain' => str_replace('https://', '', env('APP_URL', 'http://localhost:8000')),
'middleware' => [],
'prefix' => 'cookie-consent',
],
/*
|--------------------------------------------------------------------------
| Consent cookie configuration
|--------------------------------------------------------------------------
|
| In order to keep track of the user's preferences, this package stores
| an anonymized cookie. You do not need to register this cookie in the
| package's cookie manager as it is done automatically (under "essentials").
|
| The duration parameter represents the cookie's lifetime in minutes.
|
| The domain parameter, when defined, determines the cookie's activity domain.
| For multiple sub-domains, prefix your domain with "." (eg: ".mydomain.com").
|
*/
'cookie' => [
'name' => Str::slug(env('APP_NAME', 'laravel'), '_').'_cookie_consent',
'duration' => (60 * 24 * 365),
'domain' => str_replace('https://', '', env('APP_URL', 'http://localhost:8000')),
],
laraben commented
Same here, did you managed to fix it?
adriaardila commented
Having the same issue, did you find why this happened?
adriaardila commented
adriaardila commented
Ok so I got it working, in my case it was missing the EncryptCookies middleware in cookiesconsent.php
'url' => [
'domain' => null,
'middleware' => [
EncryptCookies::class,
],
'prefix' => 'cookie-consent',
],