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

Disable cookieconsent on reactive variable #630

Closed
Reconnact opened this issue Jan 31, 2024 · 3 comments
Closed

Disable cookieconsent on reactive variable #630

Reconnact opened this issue Jan 31, 2024 · 3 comments

Comments

@Reconnact
Copy link

What would be the best way to disable the popping up of the cookie consent when a variable that can be accessed from everywhere (authed) is set to true? I want to keep the whole default functionality (if no cookies are chosen show the cookie consent) but make an exception for when the user is logged in. Thanks for the help!

Originally posted by @Reconnact in #629

@github-actions github-actions bot added the triage yet to be reviewed label Jan 31, 2024
@Reconnact Reconnact changed the title What would be the best way to disable the popping up of the cookie consent when a variable that can be accessed from everywhere (authed) is set to true? I want to keep the whole default functionality (if no cookies are chosen show the cookie consent) but make an exception for when the user is logged in. Thanks for the help! Disable cookieconsent on reactive variable Jan 31, 2024
@orestbida
Copy link
Owner

If the variable can be accessed on the client side, then you can achieve this via the autoShow property.

For example, assuming the variable is called "isLoggedIn" and that it's a boolean, you would have to do something like this:

CookieConsent.run({
    autoShow: isLoggedIn !== true
    ...
})

@orestbida orestbida removed the triage yet to be reviewed label Jan 31, 2024
@Reconnact
Copy link
Author

Thanks! I combined this logic with a watch to show/hide when user is logging out/in so it feels seemless:

  watch(isLoggedIn, () => {
    const preferences = cc.getUserPreferences();
    if (isLoggedIn) {
      cc.hide();
    } else if (preferences['accepted_categories'].length == 0) {
      cc.show();
    }
  });

@orestbida
Copy link
Owner

I would suggest using the validConsent() method to determine if the plugin should be shown or not, rather than manually checking the array of categories.

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

2 participants