Database Trigger for Logged In/Out

Hi all,

Wondering if it’s possible to use database triggers to catch when a user logs in/out of my app. Reason to do this is that there are multiple places where a user could come into the app and log in, and likewise they can log out either actively or by not logging back in for a while.

I tried implementing it and these calls appear to fail. Any ideas?

1 Like

The ‘Current User is logged in’ / ‘Current User isn’t logged in’ properties will help you do this.

What if you ran a recurring workflow every minute on each page and updated the ‘last seen’ value of the Current User in the DB? That might be an easier way of approaching it. You could add an ONLY WHEN ‘Current User is logged in’ on this workflow as well.

Cheers,
Ranjit | Founder, Blur Apps
PS: If you need some 1:1 consultation, feel free to drop me a PM or email any time!

I think I was attempting to avoid having to put something on every page - this seems to me to be an elegant implementation if it worked.

When I tested it, no records were saving. NOW that I’ve waited a day, I see some new users are getting values for lastLogin. But I can’t really figure it out, because when I log in as my own personal account, no value gets stored.

Does anyone understand why this trigger condition from OP would only register for a brand new user?

I’m having the same issue myself.
This is my trigger


And what I’m trying to change.
image

The idea is that when the user logs out, I want to NULL a value in that User.
Somehow, it doesn’t work. Same if I try to set that value to something else.

I’m on Desktop (Chrome - macOS), I tested with and without debug mode. None of them work.

@emmanuel (or anyone else): Does Trigger Event - Bubble Docs is up-to-date? Maybe adding some examples? Or a new tutorial? Do triggers work? Did I miss something? Am I misusing the feature?

Regards,
Sam

I think the problem might be that the “log in/log out” information is not saved in the “User” special table. But this is a property that can only be checked on “User”, in the “only when” field.

Because only User has “is logged in” / “isn’t logged in”.

Okay, I think I see that I misunderstood the thing.
There’s this:

image
That should do it. Too bad it’s linked to a page/reusable element, and not to a backend WF.

Edit: Hmmm… still not it. I don’t think I can use “Current User” within it. Probably because by the time this triggers, there’s no longer a “Current User”.

So, my question still holds. Seems pretty bad if we cannot do something arbitrary to the user when the User logs out.