-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Description
In the JoseJwtSessionManager class, there's an issue with the cleanup of expired refresh tokens. The query to delete expired tokens is not working properly:
await this.knex(AuthRefreshTokensTable)
.where('expires_at', '<=', new Date())
.delete();This query is not successfully deleting expired tokens, likely due to issues with how JavaScript's Date objects are being converted to the database's date format.
Location
File: libs/auth/src/session/jose-jwt.ts
Lines: 152-158, 248-253, 285-290
Expected Behavior
Expired tokens should be deleted from the database when they expire.
Current Behavior
Expired tokens are not being deleted from the database, causing token accumulation over time.
Possible Fixes
- Use a raw SQL query with proper date formatting:
await this.knex.raw(`DELETE FROM ${AuthRefreshTokensTable} WHERE expires_at <= ?`, [new Date()]);- Use Knex's date formatting functions:
await this.knex(AuthRefreshTokensTable)
.where('expires_at', '<=', this.knex.fn.now())
.delete();- Format the date explicitly before using it in the query:
const now = new Date();
await this.knex(AuthRefreshTokensTable)
.where('expires_at', '<=', now.toISOString())
.delete();Impact
This issue can lead to database bloat as expired tokens accumulate over time. It may also impact performance of token-related operations and potentially cause memory issues if the table grows too large.