RAM BABU
RAM BABU

Reputation: 17

how to make ensure one active session per one user using python flask?

how to make ensure one active session per one user using python flask?

Description: if one user logged in two different machines with same credentials I want mechanism to force logout earlier active sessions of that user with flask and python. Please help me out in this.

I am currently using flask-login, load_user() and login_manager libraries for login mechanism.

Upvotes: 0

Views: 1428

Answers (1)

Ahmed Dhanani
Ahmed Dhanani

Reputation: 861

One way for ensuring this would be by generating a session id from server. You would need to generate a unique session id every time a user logs in and store it in some database against that user. Apart from this you would need to authenticate user every time an endpoint call, which requires user to be logged in, is made. And of course discard the session id on logout.

This way whenever a user logs in the old session id is discarded and the previous session no more remains valid.

Upvotes: 2

Related Questions