I'm trying to open a popup on logout, as I need to log logout reasons into a database as per requirements. Whatever I've tried though doesn't work, most likely because the session essentially reboots each time you log in or out... Has anyone done something like this before?
You will never make this reliable. You cannot stop users from disconnecting or otherwise ignoring anything like that. Or just closing the browser or the tab. "per requirements" won't magically make it possible.
I figured as much. Perhaps I'll do it before they log out, and log out after they select a reason. That will be better anyway (sometimes I try to shoehorn a solution when "replicating" parts of another platform and forget to think outside of the existing box to make it work naturally
)
Is it possible to monitor the session on the gateway end so that if it ends without the user properly logging out, you can at least make a note of that in the DB? Maybe even save the user so that you can pop up a nag screen next time they log in.
Like Phil says, you can't force the users to do a certain behavior, but you can at least make it more annoying to do the "wrong" thing than to do the "right" thing.
Of course if the session closes through no fault of the user, then an innocent user has to sit through a nag screen, but that's up to the client to decide how much they care about the logout reasons.
There is a session shutdown event that will eventually run. That could be a fallback. If you really want to be picky, you could log a special case, and check for that when they log back in. Make them answer "why did you log out at such-and-such a time?" before they can do anything else.
{ Users will absolutely hate you for that. }
Just make sure you put "Per requirements of XXX..." so users know exactly who is to blame for it