Allowing users to logout from your site

Once a user is authenticated, they can log out at <your-domain>/logout. You can provide a logout button on your authenticated pages with this link.

index.html
<a href="/logout">Log out</a>

Detecting if a user is logged in

CloudCannon sets a cookie when the user is authenticated. Use this to show the logout button for authenticated users on public pages, and hide it otherwise.

Note

No sensitive authentication data is exposed through cookies.

The cookie is used to set a class on the body. The CSS will show the logout button with this class.

script.js
var isAuthenticated = document.cookie.indexOf("authenticated=true") >= 0;

if (isAuthenticated) {
  document.body.className += " authenticated";
}
styles.css
.logout {
  display: none;
}

.authenticated .logout {
  display: block;
}
index.html
<a href="/logout" class="logout">Log out</a>d
Was this article helpful? or Suggest an improvement >