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

order of login_required annotation #833

Closed
LeiYangGH opened this issue Jan 15, 2024 · 2 comments
Closed

order of login_required annotation #833

LeiYangGH opened this issue Jan 15, 2024 · 2 comments

Comments

@LeiYangGH
Copy link

Describe the bug
if login_required is not closest to the function then seems it is not protected.

To Reproduce
Steps to reproduce the behavior:

  1. i use blueprints, and my function is like
@blueprint_name.route("/protected")
@flask_login.login_required
def protected():
  1. if i switch @flask_login.login_required and @blueprint_name.route("/protected"), then the view can be accessed without login.

Expected behavior
The annotion order doesn't matter.

@davidism
Copy link
Collaborator

davidism commented Jan 15, 2024

Decorator order matters in Python. @login @route view means "register the view, then create a new function that wraps the view with login", while @route @login view means "wrap the view with login, then register that wrapped view". This is a property of Python, and you'll want to understand this for decorators in general, not just flask-login.

@davidism davidism closed this as not planned Won't fix, can't repro, duplicate, stale Jan 15, 2024
@LeiYangGH
Copy link
Author

thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants