That's quite a tricky requirement and I would advise against creating it. However, you could try something like this:
- Create a custom login action,
- Check if the credentials are correct,
- If the credentials are correct, then:
- Check if another session for this user exists (retrieve System.Session based on the User.Name)
- Execute your custom logic microflow as that user (CommunityCommons.ExecuteMicroflowAsUser)
- Kill the user's session
- Create a new session for the user
There are many potential failure modes here:
- What if the custom logic fails, can you create a new session?
- What is the user is currently executing a long running microflow, how will that be handled?
- What if the user is currently entering data (the server doesn't know that, since the Mendix runtime is stateless)?
- What if the custom logic is taking very long?
I'm sure you can think of many more issues.