Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong example code in docs #847

Open
Jaime02 opened this issue Apr 5, 2024 · 0 comments
Open

Wrong example code in docs #847

Jaime02 opened this issue Apr 5, 2024 · 0 comments

Comments

@Jaime02
Copy link

Jaime02 commented Apr 5, 2024

Hello, I was reading this part of the docs:
https://flask-login.readthedocs.io/en/latest/#disabling-session-cookie-for-apis

from flask import g
from flask.sessions import SecureCookieSessionInterface
from flask_login import user_loaded_from_request

@user_loaded_from_request.connect
def user_loaded_from_request(app, user=None):
    g.login_via_request = True


class CustomSessionInterface(SecureCookieSessionInterface):
    """Prevent creating session from API requests."""
    def save_session(self, *args, **kwargs):
        if g.get('login_via_request'):
            return
        return super(CustomSessionInterface, self).save_session(*args,
                                                                **kwargs)

app.session_interface = CustomSessionInterface()

@user_loaded_from_request.connect
def user_loaded_from_request(self, user=None):
    g.login_via_request = True

The function user_loaded_from_request makes no sense, it is defined twice but the second time has self as argument instead of app. I don´t know what should be correct because the docs does not provide more information and context about the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant