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.

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.

So my question is, how do you get the token erased or something like that after expiry time?

After the user log in, I save the login time in a dict like this:

```
login_time[datetime.datetime.now()] = data['username']

```

and then I thought of doing something like this before or in the chat route:

```
for time, user in login_time.items():
    if datetime.datetime.now() >= time + datetime.timedelta(seconds=30):
        del login_time[time]

```

But I dont know where should I put it and how it will work.

this is a part of the chat route:

```
@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)

```