1
votes

I have been doing the Flask Web Development Book by Miguel Grinberg, and just finished up with the authorization blueprint. Though, I am having an issue that if I am already logged in, I can still put the url of the login page and go there. How can I prevent this in Flask?

While using Django, I came up with django-braces library which helps to do this, any such alternative available in Flask?

2
Just redirect the user if already logged in?Eric Workman

2 Answers

4
votes

Redirect users who are logged in navigating to the login page.

To check if they are already logged in, examine the current_user proxy. Note that logged-in users will have current_user.is_authenticated() equal True, while users who aren't logged in will have the method return False.

You have two options for the destination: back to their previous page with redirect(request.referrer) or to one of your other pages with redirect(url_for('view_name')).