I’m using Flask and Flask-Login for authentication. I have an unauthorized_handler to redirect unauthenticated users to the login page when they try to access protected resources. I want to display a flash message but it doesn’t show up on the login page after redirecting.
@LOGIN_MANAGER.unauthorized_handler
def unauthorized():
flask_login.logout_user()
flask.session.clear()
flask.flash("Session expired, please log in again.", "danger")
return flask.redirect(flask.url_for("auth.login"), code=307)
Flash message is displayed for POST request but not for GET requests.