How Log Out the Current User
What if you want to automatically log out the current user?
Use cases
- Log out a user based on a specific situation ( logging in to another location )
- Log out a user based on a certain amount of inactivity
Logout approaches
The ideal way to trigger a logout would be through the webflow.js API directly however there is no published method for doing this.
The second most ideal way you be to delete the login cookie however the cookie governing session validity is wf_sid which is an HttpOnly cookie and we cannot delete it using client-side script.
The only remaining way is to trigger a logout using Webflow's login / logout control, but from script.
The element HTML looks like this;
<button class="login-in-menu" data-wf-user-logout="Log out" data-wf-user-login="Log in" type="button">Log out</button>
Important;
- Clicking this button initiates a login / logout. Therefore, you need to determine if the user is logged in before clicking this button.
- > Use Sygnal's User Info lib to detect login state
- > Or you can compare the data-wf-user-logout attribute value here with its inner text. If they're the same, than the user is logged in, and the button reads something like "Log out".
- > This would fail if you've given your button the same text for login and logout states.
- This button must be on whatever page your logout code executes on. Putting it in your sitewide nav is best.
Inactivity Timer
An example of the code for an inactivity timer ( 15 mins );
Technical Notes
Internals notes;
FAQs
Answers to frequently asked questions.