(How do you log used codes, check if a code was previously used, and clean up old used codes in a single if statement?)
Check the last login/session/whatever for that account and if it was within the period of the TOTP that was submitted, force a relog.
(How do you log used codes, check if a code was previously used, and clean up old used codes in a single if statement?)