Flask-Login check if user is authenticated without decorator Flask-Login check if user is authenticated without decorator flask flask

Flask-Login check if user is authenticated without decorator


This is very simple in flask:

from flask_login import current_user@app.route(...)def main_route():    if current_user.is_authenticated:         return render_template("main_for_user.html")    else:         return render_template("main_for_anonymous.html")

See the documentation on anonymous users.


You could refer to the example here.

When the user has logged in, set session['logged_in']=True. At the same time, you can use Flask-login API to do some configurations in case that you want to use its functionality.
When you want to check whether the user has logged in manually rather than use the Flask-login API, then check the value of session['logged_in'].