-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add scheduled refresh token and password reset cleanup job #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7bdd183
feat: add scheduled refresh token and password reset cleanup job
GitAddRemote 0507031
feat: add TokenCleanupService implementation
GitAddRemote c1c3647
fix: correct column name in cleanup queries, remove unused ConfigServ…
GitAddRemote 8c2fc19
fix: register cleanup cron at runtime via SchedulerRegistry, add JEST…
GitAddRemote f50b7d0
fix: address PR #114 review comments on token cleanup job
GitAddRemote e90710a
fix: resolve merge conflicts with main and address PR #114 review items
GitAddRemote af8662b
fix: clarify partial index comments in token cleanup migration
GitAddRemote 778a96b
chore: bump Dockerfile base image to node:20-slim
GitAddRemote af5077a
fix: harden TokenCleanupService and its spec
GitAddRemote 1b3c7b4
chore: merge main into fix/ISSUE-98-token-cleanup-job
GitAddRemote 58cb583
fix: clarify onApplicationBootstrap comment and deduplicate default cron
GitAddRemote 9dedb81
fix: clarify migration index comments — partial indexes cover one OR …
GitAddRemote 7ddea00
chore: merge main into fix/ISSUE-98-token-cleanup-job
GitAddRemote 90d2df0
fix: register REFRESH_TOKEN_CLEANUP_CRON in env schema and migration …
GitAddRemote d00f19c
fix: replace as-any casts in token-cleanup spec with typed assertions
GitAddRemote 095dce6
refactor: centralize default cleanup cron expression in shared constant
GitAddRemote 5dba596
fix: log warning when REFRESH_TOKEN_CLEANUP_CRON is set but blank
GitAddRemote 26c7745
test: mock CronJob in token-cleanup spec to prevent timer leaks
GitAddRemote a2cde75
fix: inline boolean constants in cleanup DELETEs and fix invalid-cron…
GitAddRemote File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| FROM node:14 | ||
| FROM node:20-slim | ||
|
|
||
| # Create app directory | ||
| WORKDIR /usr/src/app | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
backend/src/migrations/1765038000000-AddTokenCleanupIndexes.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
|
||
| /** | ||
| * Adds indexes to support efficient token cleanup queries. | ||
| * | ||
| * The cleanup job deletes rows matching: | ||
| * refresh_tokens: revoked = true OR "expiresAt" < now | ||
| * password_resets: used = true OR "expiresAt" < now | ||
| * | ||
| * Partial indexes on the boolean flags keep index size small by only | ||
| * covering the rows that will actually be deleted. | ||
| */ | ||
| export class AddTokenCleanupIndexes1765038000000 implements MigrationInterface { | ||
| name = 'AddTokenCleanupIndexes1765038000000'; | ||
|
|
||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| // Partial index on revoked refresh tokens — optimizes the `revoked = true` | ||
| // predicate in the cleanup DELETE. Does not cover the expiresAt branch of | ||
| // the OR; that is handled by IDX_refresh_tokens_expiresAt below. | ||
| await queryRunner.query(` | ||
| CREATE INDEX IF NOT EXISTS "IDX_refresh_tokens_revoked" | ||
| ON "refresh_tokens" ("revoked") | ||
| WHERE "revoked" = TRUE | ||
| `); | ||
|
|
||
| // Range index for expiry-based cleanup of refresh tokens | ||
| await queryRunner.query(` | ||
| CREATE INDEX IF NOT EXISTS "IDX_refresh_tokens_expiresAt" | ||
| ON "refresh_tokens" ("expiresAt") | ||
| `); | ||
|
|
||
| // Partial index on used password resets — optimizes the `used = true` | ||
| // predicate in the cleanup DELETE. Does not cover the expiresAt branch of | ||
| // the OR; that is handled by IDX_password_resets_expiresAt below. | ||
| await queryRunner.query(` | ||
| CREATE INDEX IF NOT EXISTS "IDX_password_resets_used" | ||
| ON "password_resets" ("used") | ||
| WHERE "used" = TRUE | ||
| `); | ||
|
|
||
| // Range index for expiry-based cleanup of password resets | ||
| await queryRunner.query(` | ||
| CREATE INDEX IF NOT EXISTS "IDX_password_resets_expiresAt" | ||
| ON "password_resets" ("expiresAt") | ||
| `); | ||
| } | ||
|
GitAddRemote marked this conversation as resolved.
|
||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query( | ||
| `DROP INDEX IF EXISTS "IDX_password_resets_expiresAt"`, | ||
| ); | ||
| await queryRunner.query(`DROP INDEX IF EXISTS "IDX_password_resets_used"`); | ||
| await queryRunner.query( | ||
| `DROP INDEX IF EXISTS "IDX_refresh_tokens_expiresAt"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `DROP INDEX IF EXISTS "IDX_refresh_tokens_revoked"`, | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const DEFAULT_CLEANUP_CRON = '0 3 * * *'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.