Python Forum

Full Version: Trying to use flask_login from front end with rauth
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have posted my question here:

I am using React as frontend and Python & Flask as my backend with Rauth as OAuth2 for Facebook login and storing details of every user in db and using flask_login as protection. Those information are Sports, Education, Phone number and other things.

What I am doing is after user gets logged in I am trying to fetch his details from react app. But I am getting error user not logged in while on browser if I open that API I can see the json.

def load_user(id):
    return == id).first()

def index():
    return redirect(WEB_URL)

def logout():
    return redirect(WEB_URL)

@login_required  # After removing decorator still I am not getting
def me():
    return jsonify({'email':}), 200

def oauth_authorize(provider):
    if not current_user.is_anonymous:
        return redirect(WEB_URL)
    oauth = OAuthSignIn.get_provider(provider)
    return oauth.authorize()

def oauth_callback(provider):
    if not current_user.is_anonymous:
        return redirect(WEB_URL)
    oauth = OAuthSignIn.get_provider(provider)
    social_id, username, email = oauth.callback()
    if social_id is None:
        return redirect(WEB_URL)
    user = == social_id).first()
    if not user:
        user = User(social_id=social_id, nickname=username, email=email)
    login_user(user, True)
    return redirect(WEB_URL)
So from fronend I am calling /authorize/<provider> which then redirects to /callback/<provider> and logs user in.

Now When I am opening /me on browser it works fine returns required json or redirects me to homepage.

But when I am trying to fetch the api from frontend or Postman either I am getting user not found (if I remove the decorator login_required) or returning the whole homepage.

I am using Miguel's auth so you can check that, it's working fine.
I am getting error from the code which is like this.
Quote:Traceback (most recent call last):
File "python", line 1, in <module>
NameError: name 'login_manager' is not defined