Logout button help

I made a secure website using the included free hosting. How do I create a logout button for it?

Thank you so much!

You delete the auth cookie
something like this

const logoutBtn = document.querySelector('#YOUR-BTN-ID');
logoutBtn.addEventListener('click', logout, false);

function logout() {
  document.cookie = 'auth=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
  location.reload();
}

Here is an example
The PassKey is 123 very secure lol
https://soft-hall-6938.bss.design/

2 Likes

Thank you so much for that example!

I looked at your source code of the page, but I don’t understand where to put the code that you show above, or where your page source code invokes that code.

Sorry, if this is a simple question, but I am new to this!

Thank you so much!

Create a button on your pages (probalbly in the navbar/header) and give the button an ID of “YOUR-BTN-ID”

Then create a js file and paste the code inside your new js file

Got it! Thank you for the extra info. That helped a lot! I was able to get it to work.

Thanks again!

1 Like

Is there a way to delete the logged in version of their page from their browser’s cache when the logout button is pressed? If that’s not done, you can just hit the “back” button on the browser and it will let you back in to the password protected area.

Try adding this to the head content:

<meta http-equiv="cache-control" content="no-cache" />

This should (It’s been many years since I used it) not allow the page to cache

You might find more info here:

You can change the script like this
then the user will not be able to click the browser’s back button

const logoutBtn = document.querySelector('#YOUR-BTN-ID');
logoutBtn.addEventListener('click', logout, false);

function logout() {
  const url = 'https://YOUR-DOMAIN'
  document.cookie = 'auth=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
  location.replace(url);
}

Thank you both for the info!