20260511104500_expire_oauthAccessTokens.mjs 713 B

1234567891011121314151617181920212223242526272829
  1. import Helpers from './lib/helpers.mjs'
  2. const tags = ['server-ce', 'server-pro', 'saas']
  3. // Distinguish between access token not found and access token expired for 24h after expiry.
  4. const oneDayInSeconds = 24 * 60 * 60
  5. const indexes = [
  6. {
  7. name: 'accessTokenExpiresAt_1',
  8. key: { accessTokenExpiresAt: 1 },
  9. partialFilterExpression: { accessTokenExpiresAt: { $exists: true } },
  10. expireAfterSeconds: oneDayInSeconds,
  11. },
  12. ]
  13. const migrate = async ({ db }) => {
  14. await Helpers.addIndexesToCollection(db.oauthAccessTokens, indexes)
  15. }
  16. const rollback = async ({ db }) => {
  17. await Helpers.dropIndexesFromCollection(db.oauthAccessTokens, indexes)
  18. }
  19. export default {
  20. tags,
  21. migrate,
  22. rollback,
  23. }