title: how to add session timeout but keep session alive with user activity in flask?
body: <p>trying to tweak my user login system a bit.  using default flask session. i have a login required area (all pages under /dashboard/ - but user can be logged in sitewide as well). i want to be able to end a users session after say 30 minutes, and upon session ending, flash a message "youve been logged out for inactivity".  but if user clicks around before that period ends, keep session alive until 30 mins has passed. im getting some weird behavior with this, ie it kicks me instantly if i click around.  something is definitely wrong. I followed two questions from here - trying to combine the two features: </p>
  
  <p><a href="https://stackoverflow.com/questions/11783025/is-there-an-easy-way-to-make-sessions-timeout-in-flask">Is there an easy way to make sessions timeout in flask?</a></p>
  
  <pre><code>@app.before_request
  def make_session_permanent():
      session.modified = True        
      session.permanent = True
      app.permanent_session_lifetime = timedelta(minutes=2)
      #flash("You have been logged out for inactivity.")
  </code></pre>
  
  <p>EDIT: login behavior is normal, but time limit still does not work, session remains forever. doubt the user activity keeps session alive either.  heres the entire code for my login register system, blueprint, dashboard etc.  i dont see whats wrong. my sessions still last to infinity no matter what i try.   <a href="https://dpaste.de/vonL" rel="nofollow noreferrer">https://dpaste.de/vonL</a></p>