Prevent multiple users/session simultaneously with same username


I have built a small web app with dash. I have integrated a simple authentication that allows users to register and then login to access the site. When a user log in, I can store and get the user name for example via session.get(). Etc.

I would like to prevent multiple users to login with the same username simultaneously.

Is there a smart way of doing that? Basically to check if/which session is currently running on the app and refusing a new login while someone is currently using this username.

I was thinking simply to work with csv files on the server but I think it is not the best approach and also not sure how to handle/check when someone close the browser/session without clicking on the logoff button.

Thanks !