title: How to make a token expire after a while? (without jwt)
body: <p>I have a simple login system that I did with flask.
  After logging in, I return to the user a type of token with which the user can send messages like chat at another route.</p>
  
  <p>I would like to expire that token after some time (a minute for example), the token will expire and the user will have to log in again to get a new token.</p>
  
  <p>So my question is, how do you get the token erased or something like that after expiry time?</p>
  
  <p>After the user log in, I save the login time in a dict like this:</p>
  
  <pre><code>login_time[datetime.datetime.now()] = data['username']
  </code></pre>
  
  <p>and then I thought of doing something like this before or in the chat route:</p>
  
  <pre><code>for time, user in login_time.items():
      if datetime.datetime.now() &gt;= time + datetime.timedelta(seconds=30):
          del login_time[time]
  </code></pre>
  
  <p>But I dont know where should I put it and how it will work.</p>
  
  <p>this is a part of the chat route:</p>
  
  <pre><code>@app.route('/chat', methods=['POST'])
  def chat():
      try:
          data = request.get_json()
          username = verify_token(data['token']) # Verifying if token is in tokens list
          validate_message(data['message']) # Verifying if message is not empty
          chats.append(username + ": " + data['message'])
          for i, u in login_time.items(): # Not sure about this part
              if i != u:
                  abort(400, 'Your token is expired, please login again')
          return jsonify(chats)
  </code></pre>