Flask hit certain app route when timer ends

52 views Asked by At

I'm developing a flask application where I have implemented Azure AD based authentication. Now when user log in they can select 3 different app route based on their choice.

Inside each app route there is post method implemented on button click which start provisioning of resources such as Azure VM.

I want to start timer only when user click that button and redirect to /logout when timer ends.

Thanks in advance.

1

There are 1 answers

0
Winmari Manzano On

Have you tried doing it with sessions?

@app.route('your_url', methods = ["POST"])
def your_function():
    session.permanent = True
    app.permanent_session_lifetime = timedelta(minutes=60)

Then use some type of fetch/ajax that when you click the button at the same time a POST request to "/your_url" is triggered with an allocation of a session that would expire after 60 minutes.

Find the session you allocated and if it is not existing then proceed to logout. That's what flask-login and other flask projects seems to be doing as an approach.