I'm using Flask-Security to manage users, and I'm getting reports that users are logged-in successfully as themselves, but randomly when they load a page, it will show them logged as someone completely different. I'm not sure where I'm going wrong. What are possible ways this could happen?
I user a UserService to do some simple user management. I instantiate a user service before every request and pass in current_user.
@app.before_request def load_request_services(): g.user_service = UserService(user_datastore, application_service, email_service, ORGS, current_user)
Then, I get the current user in UserService from this method:
def current_user_get_info(self): return { 'user': self.current_user.email, 'first_name': self.current_user.first_name, 'last_name': self.current_user.last_name, 'phone_number': self.current_user.phone_number, }
this is called when this API request code is executed:
class CurrentUser(restful.Resource): def get(self): return json_response(g.user_service.current_user_get_info())
session["userid"]
is where Flask-Login/Security looks for the current user (source). So it might be worth starting from there, then working your way up through to the code you're created to find where you start noticing something odd. – Lastingapp.secret_key
is used to sign sessions, so if that stays the same between redeployments, your sessions would still be valid. – Lasting