Skip to content
New issue

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

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

Already on GitHub? # to your account

Redirect and @before_response #1

Open
Kokiro opened this issue Nov 6, 2019 · 3 comments
Open

Redirect and @before_response #1

Kokiro opened this issue Nov 6, 2019 · 3 comments

Comments

@Kokiro
Copy link

Kokiro commented Nov 6, 2019

This is an elegant plugin, thank you.

Do you have a way to redirect if the condition is not met?

Did you have the case that the condition is set before the response? In this case {% auth %} doesn't work.

@liZe
Copy link
Member

liZe commented Nov 6, 2019

This is an elegant plugin, thank you.

😄

Do you have a way to redirect if the condition is not met?

Yes, you can use the Is.xxx tests with an if condition in your route to return a redirect(…). There's no easy way I know to include this redirection in the current decorators, but you can create your own if you need to.

Did you have the case that the condition is set before the response? In this case {% auth %} doesn't work.

I'm not sure to understand the question, could you please give an example?

@Kokiro
Copy link
Author

Kokiro commented Nov 6, 2019

Let say that drunk returns False.

@app.before_request
@allow_if(Is.drunk)
def before_request():
    pass

@app.route('/'):
def home()
    ....

in the template:

{% auth 'app.home' %
    Don't show me because this route is protected by
    the decorator @allow_if(Is.drunk) which is called before the request.
{% endauth %}

@liZe
Copy link
Member

liZe commented Nov 6, 2019

Oh, I don't think I've met this situation in my use cases. You will probably need to create another decorator (instead of allow_if) that adds the auth condition to all your routes.

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

No branches or pull requests

2 participants