Help > Forum > Users > Checking if a user is logged in using JavaScript
Checking if a user is logged in using JavaScript
If you're writing custom JavaScript code in the Integrate -> HTML section and you'd like to determine if a user is logged in or what the logged in user's user ID is, you can use the following code:
<script> document.addEventListener('DOMContentLoaded', (event) => { var userid = getCookie('userid'); var loggedIn = (userid != undefined && userid != ''); }); </script>
In the example above, userid will be undefined if no user is logged in and a number if a user is logged in. It's necessary to wait until the DOMContentLoaded event fires to ensure that the necessary JavaScript libraries which contain the getCookie function are finished loading before using the function.
If you still need help, please contact us.