Streaming live at 10am (PST)

Cookie delete script makes page reload constantly

I’m trying to create a faux log-out from a password protected page. My logic was that I could simply delete the auth cookie (using this method), and then reload the page.

However, it seems that my function sends the page into an endless reload loop, without even having to click on the log-out button.

What could be causing this?

Here is my script:

  const logOutBtn = document.querySelector('#log-out-btn');
  const logOutFaux = function() {
    var cookieString = 'wf_auth_page=';
    var expiryDate = new Date();
    expiryDate.setTime(expiryDate.getTime() - 86400 * 1000);
    cookieString += ';max-age=0';
    cookieString += ';expires=' + expiryDate.toUTCString();
    document.cookie = cookieString;
  logOutBtn.addEventListener('click', logOutFaux());

Here is my site Read-Only: LINK

@peej - can you post the live site? It seems unlikely that a click event is occurring to trigger the function without a click actually occurring, but maybe there is a conflict with another script?

1 Like

sorry about that, I updated the read-only link

@peej - can you post the published site so I can inspect the page and see what is happening? I can’t test custom code in the read-only.

If you need, the password is ‘arctest’

@peej - is the script currently commented out?

My bad, I’ve uncommented it. Thank you for bearing with me

Try something like this:

logOutBtn.addEventListener("click", function (){
1 Like

Thanks, that stops the page from reloading automatically. It seems like the cookie doesn’t get removed though, do you have any suggestions on how I may approach that?

@peej - looks like it may not be possible as the cookie has the HttpOnly flag set:

Oh wow. That’s really frustrating. Thanks for the answer!