Skip to content

feat: add scheduled refresh token and password reset cleanup job#114

Open
GitAddRemote wants to merge 2 commits intomainfrom
fix/ISSUE-98-token-cleanup-job
Open

feat: add scheduled refresh token and password reset cleanup job#114
GitAddRemote wants to merge 2 commits intomainfrom
fix/ISSUE-98-token-cleanup-job

Conversation

@GitAddRemote
Copy link
Copy Markdown
Owner

Summary

  • Adds TokenCleanupService to the auth module with a @Cron job (default: 0 3 * * * — 3am daily)
  • Deletes refresh_tokens rows where revoked = true OR expires_at < NOW()
  • Deletes password_resets rows where used = true OR expires_at < NOW()
  • Cron expression is configurable via REFRESH_TOKEN_CLEANUP_CRON env var
  • Job skips early when NODE_ENV=test; ScheduleModule is already excluded in test env via AppModule
  • Logs deleted row count and duration on success; logs error stack on failure without rethrowing

Test plan

  • Set REFRESH_TOKEN_CLEANUP_CRON="* * * * *" locally and confirm log output after 1 minute
  • Confirm revoked/expired rows are removed from both tables
  • Confirm job does not run in test environment (unit tests do not hang)
  • Confirm REFRESH_TOKEN_CLEANUP_CRON documented in .env.example

Closes #98

Add TokenCleanupService to the auth module with a @Cron job that
runs daily at 3am (configurable via REFRESH_TOKEN_CLEANUP_CRON) and
deletes all refresh_tokens rows where revoked=true or expires_at < now,
and all password_resets rows where used=true or expires_at < now.

- Job skips early when NODE_ENV=test
- Logs row count and duration on success, error stack on failure
- Does not rethrow on failure so job errors cannot crash the process
- ScheduleModule is already conditionally excluded in test env (AppModule)

Closes #98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tech Story: Add scheduled refresh token cleanup job

1 participant