I want to restrict logged-in users to only have one active session, i.e. if the user logs in with a new sessionid, the old session should be terminated. I found a lot of hel
You can always use this approach though not recommended, it works.
my_old_sessions = Session.objects.all()
for row in my_old_sessions:
if row.get_decoded().get("_username") == request.user.username:
row.delete()
You would implement the code above in your login() function right before authenticating the user.
This of course only works if you have a login() function method that stores the USERS username in his session like follows:
request.session["_username"] = request.user.username
If you use this approach just remember to empty your database of all of your sessions before running your server after you've made these changes because it will raise KeyLookUp errors.