Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Logout with native functions

If your app is configured to require users to log in before they can access the content, and you are already using the nativeFunctions.login() to log users in, you will want to implement the nativeFunctions.logout() function as well.

When triggered, the nativeFunctions.logout() will clear all cookies and sessions in the app, and reload the app, taking the user back to the login screen.

Imagine a situation where while browsing your app the user gets logged out because his cookies expired, if the nativeFunctions.logout() function is not triggered the user will see your website’s error messages for blocked content, and the user experience might get confusing for the user.

Instead, you should take the user to the login screen so he can provide his credentials and re-login accordingly.

You can call the nativeFunctions.logout() after you have confirmed that the user is not logged in:

<script type="text/javascript">
    // Get the user agent and convert it to lowercase for case-insensitive comparison
    var userAgent = navigator.userAgent.toLowerCase();

    // Log the user out directly if the user agent contains 'canvas'
    function appLogout() {
        try {
            // Check if the user agent contains the string "canvas"
            if (userAgent.indexOf('canvas') > -1) {
                nativeFunctions.logout();
            }
        } catch (ex) {
            console.log(ex.message);
        }
    }
</script>