Answer the question
In order to leave comments, you need to log in
How to force logout in flask?
Good day! How to force logout for a user in flask if the same user logs in through another device? The flask-login library is used, there is also a version with flask-httpauth
Answer the question
In order to leave comments, you need to log in
Maybe shove it into before_request something like this?
@app.before_request
def before_request():
user_id = session.get('user_id', None)
# Дальше проверяем, есть ли у user_id другие открытые сессии.
# Если сессия есть, то
# session.clear()
In the flask-login settings, I found such a session_protection parameter, this is an attribute of the LoginManager instance.
login_manager = LoginManager()
login_manager.session_protection = 'strong'
If session_protection == 'strong' the session will be forced to end if the client tries to log in from different browsers and different IPs. But I try to log in from a computer and from a phone, authorization passes without problems
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question