deleteJwt Last updated: 30. May 2026

API only function

The deleteJwt function is responsible for removing the current (if any) JWT (JSON Web Token) secure cookie from the user's browser.

See also: writeJwt denyAccess logOut flagActivity getProfilePictureUrl Custom JWT login example

Parameters

This function takes no parameters

Returns

True if successful.

Example

Code example (#JS)

#JS is mixed HTML (or other text file) with inline JavaScript with # starting and ending each inline statement.
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Log out!</title>
</head>
<body style="font-size:2em; text-align:center; font-family: arial; margin-top:2em;">
    <div id="message">You are now logging out! ⏳</div>
    <a style="display:none" id="link1" href="/">Log in again</a>
    <script>
        // Static logout page. Hash templates are cached, so the actual
        // cookie removal must happen in an API endpoint that calls
        // docly.deleteJwt(). This page just fetches that endpoint.
        fetch('/API/logout')
            .then(response => response.json())
            .then(data => {
                document.getElementById('message').innerText = 'You are now logged out!';
                document.getElementById('link1').style.display = '';
            })
            .catch(error => {
                document.getElementById('message').innerText = 'Error during logout: ' + error.message;
                console.error('Error:', error);
            });
    </script>
</body>
</html>

Output

The #JS code above produces the output shown below:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Log out!</title>
</head>
<body style="font-size:2em; text-align:center; font-family: arial; margin-top:2em;">
    <div id="message">You are now logging out! ⏳</div>
    <a style="display:none" id="link1" href="/">Log in again</a>
    <script>
        // Static logout page. Hash templates are cached, so the actual
        // cookie removal must happen in an API endpoint that calls
        // docly.deleteJwt(). This page just fetches that endpoint.
        fetch('/API/logout')
            .then(response => response.json())
            .then(data => {
                document.getElementById('message').innerText = 'You are now logged out!';
                document.getElementById('link1').style.display = '';
            })
            .catch(error => {
                document.getElementById('message').innerText = 'Error during logout: ' + error.message;
                console.error('Error:', error);
            });
    </script>
</body>
</html>

Code example (JS)

JS is normal JavaScript either running in the browser or on the Docly™ server.
// Log a user out by removing their JWT cookie
docly.deleteJwt();


// Typical use in a logout API endpoint:
// #/API/logout.js
export default () => {
    docly.deleteJwt();
    return { success: true };
}


// Note: deleteJwt() removes a custom JWT cookie set by writeJwt().
// To log a user out of the built-in Docly session, use docly.logOut() instead.