backend.utils.token_cleanup
Token cleanup utility.
Removes expired and revoked tokens from the database to keep the token tables lean. Intended to be called once at application startup and optionally on a recurring schedule.
- Cleaned up tables:
models.UsedPasswordResetToken– entries older than 48 hmodels.TokenBlacklist– entries whoseexpires_atis in the pastmodels.RefreshToken– revoked entries older than 48 h and all entries whoseexpires_atis in the past
- backend.utils.token_cleanup.cleanup_expired_tokens(db)[Quellcode]
Delete expired and revoked tokens from the database.
- Parameter:
db (Session) – Active SQLAlchemy database session.
- Rückgabe:
A summary dictionary with the number of removed rows per category:
{ "password_reset": int, "blacklist": int, "revoked_refresh": int, "expired_refresh": int, }
- Rückgabetyp:
- Verursacht:
Exception – Re-raises any database exception after rolling back the transaction.