This feature is only available for Sites hosted through CloudCannon. If you host your Site externally, or use CloudCannon in Headless Mode, this feature will not work.
When you enable password authentication, enable user account authentication, or enable SAML authentication, CloudCannon attaches a cookie to the visitor's web browser when they have successfully logged in (i.e., authenticated). CloudCannon uses this cookie to allow access when a user requests an authenticated route.
No sensitive authentication data is exposed through cookies.
This cookie is removed if a visitor clears their Internet browser cache.
You can allow authenticated users to log out by adding a logout link to your authenticated routes. CloudCannon reserves the /logout
route on all Sites. The logout URL for your Site will be your domain name followed by /logout
, even if you serve your Site on a subdomain, or subpath, CloudCannon w (e.g., example.com/logout
, app.example.com/logout
, or example.com/documentation/logout
).
CloudCannon reserves the /logout
URL for all Sites hosted on CloudCannon, even if you do not have a CloudCannon authentication method enabled. You cannot serve any content on this URL.
When a visitor clicks the logout link, CloudCannon removes the cookie and redirects them to your home page.
You can create a logout button on your authenticated pages using the following link:
<a href="/logout">Log out</a>
If you use authenticated routes, your public pages may have a mix of authenticated and non-authenticated users. In this case, you can use JavaScript and CSS to show the logout button only to authenticated users.
var isAuthenticated = document.cookie.indexOf("authenticated=true") >= 0;
if (isAuthenticated) {
document.body.classList.add("authenticated");
}
.logout {
display: none;
}
.authenticated .logout {
display: block;
}
<a href="/logout" class="logout">Log out</a>
In the above example, the user's browser will add the authenticated
class to the body
element of your page if they have the authenticated
cookie. The CSS file will only display elements with the .logout
class if nested within an element with the .authenticated
class.