Skip to content

Implement Automated Refresh Token Cleanup and Schema Optimization #543

@Harxhit

Description

@Harxhit

Summary

Implement automated cleanup for revoked and expired refresh tokens, add database indexing to support efficient cleanup operations, and provide verification that the cleanup process works correctly.

Contexts

The authentication system now supports refresh token rotation, revocation, session tracking, and token families.

As users continue to authenticate and refresh sessions, revoked and expired refresh tokens will accumulate in the database. Without a cleanup mechanism, the refresh_tokens table will continue to grow unnecessarily, increasing storage usage and potentially impacting query performance.

Since cleanup operations will frequently query revoked and expired tokens, the schema should also be reviewed and optimized with appropriate indexes to ensure efficient lookups and deletion operations.

This work requires updates across the database schema, cleanup infrastructure, testing, and operational verification.

Tasks

  • Implement a scheduled cleanup job for refresh tokens
  • Remove revoked refresh tokens automatically
  • Remove expired refresh tokens automatically
  • Add logging for cleanup execution and deletion statistics
  • Review the RefreshToken schema for cleanup-related query patterns
  • Add or optimize indexes required for efficient cleanup operations
  • Add automated tests covering cleanup behavior
  • Verify that active refresh tokens are never removed
  • Record a demo video showing successful cleanup of revoked and expired refresh tokens

Acceptance Criteria

  • Revoked refresh tokens are automatically deleted
  • Expired refresh tokens are automatically deleted
  • Active refresh tokens remain untouched
  • Cleanup executes on a scheduled interval
  • Cleanup execution is logged
  • Appropriate indexes exist for cleanup-related queries
  • Tests validate cleanup behavior
  • Demo video shows successful cleanup of revoked and expired refresh tokens
  • No regression in authentication or refresh-token flows

Area

backend

Difficulty

Hard

Metadata

Metadata

Assignees

Labels

backenddevopshardComplex task requiring extensive changes.

Type

No type
No fields configured for issues without a type.

Projects

Status
Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions