New (and imho improved) way to log out other user's sessions

I’ve been exploring Bubble’s native “log out other user’s sessions” action, and while it achieves the technical goal of logging out, it hasn’t met my experience goals for customers. Specifically: I want to take the recently logged out user to my login page, and show a message on that logged out device (and only that device). Versus silently breaking the app.

Here’s what I came up with to deliver my experience:

  • Create a new custom state lastSessionClient, and a new DB field in User, lastSessionServer
  • On initial login, set lastSessionClient to Current Timestamp, and then set lastSessionServer to lastSessionClient
  • Now set a WF, Whenever lastSessionClient is not lastSessionServer → log the user out

In other words: lastSessionClient will almost always equal lastSessionServer. The only time it doesn’t is when the user has logged in on another device, and while Client = Server on the most recent device, Client != Server on the previous device.

As a result, I’m able to run WF on the now logged-out device → log out, show the login page, show the alert. For me, this is much better than silently breaking the app on a device, and waiting for users to figure it out.

Hope this helps! And if you think the above approach is terrible for some reason, I welcome that feedback too :wink: (In the meantime, I’m just excited that it’s working!)

1 Like