Here’s one way to do it:
When a user logs in, create an object of an entity that is associated to that user’s session. Set the association’s on delete behavior to delete that object when the session is deleted. Finally, on that object, create a before or after-delete microflow to perform your logic.
This widget might help you: https://appstore.home.mendix.com/link/app/113622/AuraQ-Limited/Session-Timeout
widgets are at front-end, it is java script running is browser, we’d better have some way to subscribe session timeout event at back-end.