Webflow User Accounts ( Memberships )

Log Out User

No items found.
Overview
Getting Started with Memberships
000
Memberships Current Features
001
Memberships Roadmap
002
What is Memberships Good For?
003
Customizing Membership UI
Building a Custom Login/Logout Button
Adv
8:50
110
Combining Log In / Sign Up into a Single Tabbed Page
Adv
8:41
111
Conditional Element Display, on Log-in State
Adv
7:34
112
Access-Group-Specific Sign-Up Forms
Adv
113
Customizing Membership Flow
Redirect Users to a Specific Page after Login
Adv
4:11
201
Redirect Users to a Specific Page after Registration
Adv
202
Log Out User
Adv
202
Getting Member Data
Getting the Logged-In User's Info
Adv
10:18
401
Getting the User's Webflow User ID
Adv
4:11
402
Customizing the Member UX
Customizing Webflow Site Search for User Accounts
Adv
601
SEO & Content Preview Approaches
Adv
602
Addendum
Other Membership Solutions
901
Memberships Loader
902
No items found.

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 );

let timeout;

// Start a timeout when the page loads
resetTimeout();

// Reset the timeout whenever the user interacts with the page
window.addEventListener('mousemove', resetTimeout);
window.addEventListener('mousedown', resetTimeout);
window.addEventListener('keypress', resetTimeout);
window.addEventListener('scroll', resetTimeout);
window.addEventListener('touchmove', resetTimeout);

function resetTimeout() {
  // Clear the existing timeout
  clearTimeout(timeout);

  // Start a new timeout
  timeout = setTimeout(logout, 15 * 60 * 1000); // 15 minutes
}

function logout() {
  // Log the user out (or whatever you want to do when the timeout expires)
  console.log('Logging out due to inactivity');
}

Technical Notes

Internals notes;

function rU(e) { e.preventDefault(), nU().then(()=>{ window.Webflow.location("/") } ) } function nU() { return VDe.userSystemsRequestClient.mutate({ mutation: YDe.logoutMutation }) }
Table of Contents
Did we just make your life better?
Passion drives our long hours and late nights supporting the Webflow community. Click the button to show your love.