Question

How to Skip Login Page if Active Session Exists in Flask Application.

Currently i have the Flask Application, after the successful login, am redirecting the Page to Index -

http://example.com/ --> Post Login --> http://example.com/index (Sucess)

However, when the Active Session Exists, and when i try http://example.com/ , It takes me to Login Page Again.

Was it helpful?

Solution

In your login handler, simply check if the user is logged in early in the function. For example, if you're using Flask-Login:

def login():
    if current_user.is_authenticated():
        return redirect(url_for('index'))
    # process login for anon user
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top