2

I have implemented a web server using python flask and hosted in pythonanywhere.com ... I have used global variables in my implementation for handle login sessions. for example-

TOKENS = {"OAUTH_TOKEN": ""}
if(TOKENS['OAUTH_TOKEN']) == "":
   authorized = Flase
else:
   authorized = True

But the problem is when a user logged and authorized the second user get as a authorized user. pythonanywhere used WSGI as a server for run python flask web application. How can I handle each user as separates threads?

2 Answers 2

5

You can write your code to create a login solotion but It's not realy safe.need to set the login credential in the session and load the user with each request and load it in each request and set g object.

#login
session['user'] = user_id


@app.before_request
def before_request():
    current_user = user_obj
    g.user = current_user

You can use this guide for a good login app.

Sign up to request clarification or add additional context in comments.

Comments

3

You can use Flask-Login extension. It can handle most of typical user-management activities out-of-the-box.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.