Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The cookie not saved after server respond with {"status": "ok"} #62

Open
szotyi41 opened this issue Sep 9, 2024 · 4 comments
Open

The cookie not saved after server respond with {"status": "ok"} #62

szotyi41 opened this issue Sep 9, 2024 · 4 comments

Comments

@szotyi41
Copy link

szotyi41 commented Sep 9, 2024

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')),
    ],
Képernyőfotó 2024-09-09 - 12 47 03
@laraben
Copy link

laraben commented Nov 20, 2024

Same here, did you managed to fix it?

@adriaardila
Copy link

Having the same issue, did you find why this happened?

@adriaardila
Copy link

I found something, when loading the provider (CookiesServiceProvider) preferences are set, but when I call the script at the end of the head of the layout:

@cookieconsentscripts

$preferences are always set to null.

image

@adriaardila
Copy link

adriaardila commented Dec 19, 2024

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',
    ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants